public static bool Prefix(MenuScript __instance, ref int ___curHostPort, ref bool ___playing)
 {
     MonoBehaviour.print("Hosting Game");
     try
     {
         ___curHostPort = int.Parse(__instance.txtHostPort[0].text);
     }
     catch (Exception)
     {
         ___curHostPort = 7777;
         __instance.txtHostPort[0].text = string.Empty;
         __instance.txtHostPort[1].text = __instance.txtHostPort[0].text;
     }
     Network.InitializeServer(GadgetCoreConfig.MaxConnections, ___curHostPort, false);
     if (GadgetCoreConfig.UseUPnP)
     {
         int curHostPort = ___curHostPort;
         try
         {
             __instance.StartCoroutine(GadgetCore.CoreLib.ForwardPort(curHostPort));
         }
         catch (System.IO.FileNotFoundException)
         {
             GadgetCore.Log("Gadget Core was unable to perform UPnP Port Forwarding because Gadget Core's zip file has not been unpacked!");
         }
         catch (Exception e)
         {
             GadgetCore.Log("The following error occured while attempting to perform UPnP Port Forwarding:" + Environment.NewLine + e.ToString());
         }
     }
     ___playing = false;
     return(false);
 }
Esempio n. 2
0
 internal static void ParseIDMatrixData(string packedData)
 {
     IsHostVanilla = false;
     MatrixReady   = false;
     try
     {
         foreach (string dicEntry in packedData.Split('|'))
         {
             string[] splitDic = dicEntry.Split(new char[] { ':' }, 2);
             if (GameRegistry.IsRegistryRegistered(splitDic[0]))
             {
                 Registry reg = GameRegistry.GetRegistry(splitDic[0]);
                 IDConversionMatrixToHost[reg.GetRegistryName()]  = new Dictionary <int, int>();
                 IDConversionMatrixToLocal[reg.GetRegistryName()] = new Dictionary <int, int>();
                 foreach (string regEntry in splitDic[1].Split(','))
                 {
                     string[] splitReg = regEntry.Split('=');
                     if (reg.reservedIDs.ContainsKey(splitReg[0]))
                     {
                         int hostID = int.Parse(splitReg[1]);
                         IDConversionMatrixToHost[reg.GetRegistryName()][reg.reservedIDs[splitReg[0]]] = hostID;
                         IDConversionMatrixToLocal[reg.GetRegistryName()][hostID] = reg.reservedIDs[splitReg[0]];
                     }
                 }
             }
         }
         MatrixReady = true;
     }
     catch (Exception e)
     {
         GadgetCore.Log("Received bad host ID conversion data: " + packedData);
         GadgetCore.Log("Exception that occured while parsing host ID conversion data:" + Environment.NewLine + e.ToString());
         Network.Disconnect();
     }
 }
Esempio n. 3
0
 public static void Prefix(GameScript __instance)
 {
     InstanceTracker.GameScript = __instance;
     GadgetCore.GenerateSpriteSheet();
     GadgetUtils.SafeCopyTexture(__instance.TileManager.GetComponent <ChunkWorld>().Texture, 0, 0, 0, 0, 128, 128, GadgetCoreAPI.spriteSheet, 0, 0, 0, 0);
     __instance.TileManager.GetComponent <ChunkWorld>().Texture = GadgetCoreAPI.spriteSheet;
     __instance.WallManager.GetComponent <ChunkWorld>().Texture = GadgetCoreAPI.spriteSheet;
     foreach (GadgetModInfo mod in GadgetMods.ListAllModInfos())
     {
         __instance.gameObject.AddComponent <GadgetModHookScript>().Mod = mod;
     }
 }
Esempio n. 4
0
 public static bool Prefix(Menuu __instance, ref Ray ___ray, ref RaycastHit ___hit)
 {
     if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
     {
         ___ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(___ray, out ___hit, 10f))
         {
             if (___hit.transform.gameObject.name.Equals("bModMenu"))
             {
                 __instance.GetComponent <AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/confirm"), Menuu.soundLevel / 10f);
                 if (GadgetCore.IsUnpacked)
                 {
                     __instance.StartCoroutine(ModMenu(__instance));
                 }
                 else
                 {
                     __instance.StartCoroutine(UnpackGadgetCore());
                 }
                 return(false);
             }
             else if (___hit.transform.gameObject.name.Equals("bQuit"))
             {
                 foreach (System.Diagnostics.Process process in ModDescPanelController.ConfigHandles)
                 {
                     if (process != null && !process.HasExited)
                     {
                         process.Kill();
                     }
                 }
             }
             else if (___hit.transform.gameObject.name.Equals("bPlay") && !GadgetCore.IsUnpacked)
             {
                 GadgetCore.Log(GadgetCoreAPI.GetCursorPos().ToString());
                 GameObject gameObject = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("txtError"), GadgetCoreAPI.GetCursorPos() + new Vector3(0, 0, 9), Quaternion.identity);
                 gameObject.SendMessage("InitError", "You must unpack Gadget Core before playing!");
                 return(false);
             }
         }
     }
     return(true);
 }
Esempio n. 5
0
 internal static void RegisterRegistry(Registry registry)
 {
     GadgetCore.Log("Initializing " + registry.GetRegistryName() + " Registry");
     registries.Add(registry.GetEntryType(), registry);
     registriesByName.Add(registry.GetRegistryName(), registry);
 }
        /// <summary>
        /// Loads the given config file, and adds all of the entries within to this <see cref="UMFGadgetConfigMenu"/>
        /// </summary>
        protected virtual void LoadConfigFile(string configFilePath, string section, params string[] readonlyEntries)
        {
            if (!File.Exists(configFilePath))
            {
                AddComponent(new GadgetConfigLabelComponent(this, "No Config File", "This mod had no config file when this menu was generated."));
                AddComponent(new GadgetConfigLabelComponent(this, "No Config File", "Perhaps it was just installed?"));
                AddComponent(new GadgetConfigLabelComponent(this, "No Config File", "Click the button to reload this config menu."));
                AddComponent(new GadgetConfigSpacerComponent(this, "Spacer"));
                AddComponent(new GadgetConfigButtonComponent(this, null, "Refresh Config File", () =>
                {
                    Reset();
                }, 0.25f));
                return;
            }
            ConfigFilePath    = configFilePath;
            ConfigFileSection = section;
            ReadonlyEntries   = readonlyEntries;
            IniParser         = new FileIniDataParser();
            Ini = IniParser.ReadFile(configFilePath);
            Ini.Configuration.SkipInvalidLines = true;
            Ini.Configuration.AssigmentSpacer  = "";
            if (section == null || !Ini.Sections.ContainsSection(section))
            {
                section = Path.GetFileNameWithoutExtension(configFilePath);
                if (!Ini.Sections.ContainsSection(section))
                {
                    throw new InvalidOperationException(NO_CONFIGURABLE_DATA);
                }
            }
            AddComponent(new GadgetConfigLabelComponent(this, "ConfigVersion", "Config Version (not to be confused with mod version): " + Ini["uModFramework"]["ConfigVersion"]), GadgetConfigComponentAlignment.HEADER);
            bool firstStandard = true, firstHeader = false, firstFooter = true;

            foreach (KeyData keyData in Ini[section])
            {
                if (keyData == null)
                {
                    continue;
                }
                GadgetConfigComponentAlignment alignment = default;
                bool seperatorMade = false, commentsMade = false;
                try
                {
                    string dataTypeString  = keyData.Comments.SingleOrDefault((x) => x.StartsWith("[Type:"));
                    string dataRangeString = null;
                    if (!string.IsNullOrEmpty(dataTypeString))
                    {
                        string[] dataTypeStrings = dataTypeString.Split('|');
                        dataTypeString = dataTypeStrings[0];
                        if (dataTypeStrings.Length > 1)
                        {
                            dataRangeString = dataTypeStrings[1].Substring(8, dataTypeStrings[1].Length - 9);
                        }
                        dataTypeString = dataTypeString.Substring(7, dataTypeString.Length - 8);
                    }
                    else
                    {
                        dataTypeString = "String";
                    }
                    string defaultValueString = keyData.Comments.SingleOrDefault((x) => x.StartsWith("[Default(s):"));
                    string vanillaValueString = keyData.Comments.SingleOrDefault((x) => x.StartsWith("[Vanilla:"));
                    if (!string.IsNullOrEmpty(defaultValueString) && defaultValueString != "[Default(s): n/a]")
                    {
                        string[] defaultValueStrings = defaultValueString.Split('|');
                        defaultValueString = defaultValueStrings[0];
                        if (defaultValueStrings.Length > 1)
                        {
                            vanillaValueString = defaultValueStrings[1].Substring(10, defaultValueStrings[1].Length - 11);
                        }
                        defaultValueString = defaultValueString.Substring(13, defaultValueString.Length - 14);
                    }
                    else if (!string.IsNullOrEmpty(vanillaValueString) && vanillaValueString != "[Vanilla: n/a]")
                    {
                        vanillaValueString = vanillaValueString.Substring(10, vanillaValueString.Length - 11);
                    }
                    else
                    {
                        defaultValueString = null;
                    }
                    string allowedValuesString = keyData.Comments.SingleOrDefault((x) => x.StartsWith("[Allowed:"));
                    if (!string.IsNullOrEmpty(allowedValuesString))
                    {
                        allowedValuesString = allowedValuesString.Substring(10, allowedValuesString.Length - 11);
                    }
                    else
                    {
                        allowedValuesString = null;
                    }
                    string requiresRestartString = keyData.Comments.SingleOrDefault((x) => x.StartsWith("[Restart:"));
                    if (!string.IsNullOrEmpty(requiresRestartString))
                    {
                        requiresRestartString = requiresRestartString.Substring(10, requiresRestartString.Length - 11);
                    }
                    else
                    {
                        requiresRestartString = null;
                    }
                    bool requiresRestart = requiresRestartString != null?bool.Parse(requiresRestartString) : false;

                    GadgetConfigComponentAlignment?nullableAlignment = AlignConfigEntry(keyData.KeyName);
                    if (nullableAlignment == null)
                    {
                        continue;
                    }
                    alignment = (GadgetConfigComponentAlignment)nullableAlignment;
                    if ((alignment == GadgetConfigComponentAlignment.STANDARD && firstStandard == true) || (alignment == GadgetConfigComponentAlignment.HEADER && firstHeader == true) || (alignment == GadgetConfigComponentAlignment.FOOTER && firstFooter == true))
                    {
                        switch (alignment)
                        {
                        case GadgetConfigComponentAlignment.STANDARD:
                            firstStandard = false;
                            break;

                        case GadgetConfigComponentAlignment.HEADER:
                            firstHeader = false;
                            break;

                        case GadgetConfigComponentAlignment.FOOTER:
                            firstFooter = false;
                            break;
                        }
                    }
                    else
                    {
                        AddComponent(new GadgetConfigSeparatorComponent(this, "Seperator"), alignment);
                    }
                    seperatorMade = true;
                    foreach (string comment in keyData.Comments)
                    {
                        if (!string.IsNullOrEmpty(comment) && comment[0] != '[')
                        {
                            AddComponent(new GadgetConfigLabelComponent(this, "Comment For: " + keyData.KeyName, comment, 0.05f, true), alignment);
                        }
                    }
                    commentsMade = true;
                    switch (dataTypeString)
                    {
                    case "Boolean":
                        bool boolValue        = bool.Parse(keyData.Value);
                        bool?boolDefaultValue = defaultValueString != null ? (bool?)bool.Parse(defaultValueString) : null;
                        bool?boolVanillaValue = vanillaValueString != null ? (bool?)bool.Parse(vanillaValueString) : null;
                        AddComponent(new GadgetConfigBoolComponent(this, keyData.KeyName, boolValue, (b) => SetConfigValue(section, keyData.KeyName, b.ToString()), readonlyEntries.Contains(keyData.KeyName), boolDefaultValue, boolVanillaValue), alignment);
                        break;

                    case "Int32":
                        int   intValue = int.Parse(keyData.Value);
                        int[] intRange = dataRangeString?.Split(',').Select(x => int.Parse(x)).ToArray();
                        if (intRange != null && intRange.Length != 2)
                        {
                            throw new InvalidDataException("The range '" + dataRangeString + "' is not valid!");
                        }
                        int?intDefaultValue = defaultValueString != null ? (int?)int.Parse(defaultValueString) : null;
                        int?intVanillaValue = vanillaValueString != null ? (int?)int.Parse(vanillaValueString) : null;
                        AddComponent(new GadgetConfigIntComponent(this, keyData.KeyName, intValue, (s) => SetConfigValue(section, keyData.KeyName, s.ToString()), intRange != null ? intRange[0] : 0, intRange != null ? intRange[1] : 0, readonlyEntries.Contains(keyData.KeyName), intDefaultValue, intVanillaValue), alignment);
                        break;

                    case "Single":
                        float   floatValue = float.Parse(keyData.Value);
                        float[] floatRange = dataRangeString?.Split(',').Select(x => float.Parse(x)).ToArray();
                        if (floatRange != null && floatRange.Length != 2 && floatRange.Length != 3)
                        {
                            throw new InvalidDataException("The range '" + dataRangeString + "' is not valid!");
                        }
                        float?floatDefaultValue = defaultValueString != null ? (float?)float.Parse(defaultValueString) : null;
                        float?floatVanillaValue = vanillaValueString != null ? (float?)float.Parse(vanillaValueString) : null;
                        AddComponent(new GadgetConfigFloatComponent(this, keyData.KeyName, floatValue, (s) => SetConfigValue(section, keyData.KeyName, s.ToString()), floatRange != null ? floatRange[0] : 0, floatRange != null ? floatRange[1] : 0, floatRange != null && floatRange.Length == 3 ? (int)floatRange[2] : -1, readonlyEntries.Contains(keyData.KeyName), floatDefaultValue, floatVanillaValue), alignment);
                        break;

                    case "Double":
                        double   doubleValue = double.Parse(keyData.Value);
                        double[] doubleRange = dataRangeString?.Split(',').Select(x => double.Parse(x)).ToArray();
                        if (doubleRange != null && doubleRange.Length != 2 && doubleRange.Length != 3)
                        {
                            throw new InvalidDataException("The range '" + dataRangeString + "' is not valid!");
                        }
                        double?doubleDefaultValue = defaultValueString != null ? (double?)double.Parse(defaultValueString) : null;
                        double?doubleVanillaValue = vanillaValueString != null ? (double?)double.Parse(vanillaValueString) : null;
                        AddComponent(new GadgetConfigDoubleComponent(this, keyData.KeyName, doubleValue, (s) => SetConfigValue(section, keyData.KeyName, s.ToString()), doubleRange != null ? doubleRange[0] : 0, doubleRange != null ? doubleRange[1] : 0, doubleRange != null && doubleRange.Length == 3 ? (int)doubleRange[2] : -1, readonlyEntries.Contains(keyData.KeyName), doubleDefaultValue, doubleVanillaValue), alignment);
                        break;

                    case "String":
                        string stringValue        = keyData.Value;
                        string stringDefaultValue = defaultValueString;
                        string stringVanillaValue = vanillaValueString;
                        if (keyData.Comments.Contains("[IsKeyBind: True]"))
                        {
                            AddComponent(new GadgetConfigKeybindComponent(this, keyData.KeyName, stringValue, (s) => SetConfigValue(section, keyData.KeyName, s), true, readonlyEntries.Contains(keyData.KeyName), stringDefaultValue, stringVanillaValue), alignment);
                        }
                        else
                        {
                            AddComponent(new GadgetConfigStringComponent(this, keyData.KeyName, stringValue, (s) => SetConfigValue(section, keyData.KeyName, s), readonlyEntries.Contains(keyData.KeyName), stringDefaultValue, stringVanillaValue), alignment);
                        }
                        break;

                    case "String[]":
                        string[] stringArrayValue        = keyData.Value.Split(',');
                        string[] stringArrayDefaultValue = defaultValueString?.Split(',');
                        string[] stringArrayVanillaValue = vanillaValueString?.Split(',');
                        if (keyData.Comments.Contains("[IsKeyBind: True]"))
                        {
                            AddComponent(new GadgetConfigMultiKeybindComponent(this, keyData.KeyName, stringArrayValue, (s) => SetConfigValue(section, keyData.KeyName, s?.Aggregate(new StringBuilder(), (x, y) => { if (x.Length > 0)
                                                                                                                                                                                                                      {
                                                                                                                                                                                                                          x.Append(',');
                                                                                                                                                                                                                      }
                                                                                                                                                                                                                      x.Append(y); return(x); })?.ToString()), true, readonlyEntries.Contains(keyData.KeyName), stringArrayDefaultValue, stringArrayVanillaValue), alignment);
                        }
                        else
                        {
                            AddComponent(new GadgetConfigMultiStringComponent(this, keyData.KeyName, stringArrayValue, (s) => SetConfigValue(section, keyData.KeyName, s?.Aggregate(new StringBuilder(), (x, y) => { if (x.Length > 0)
                                                                                                                                                                                                                     {
                                                                                                                                                                                                                         x.Append(',');
                                                                                                                                                                                                                     }
                                                                                                                                                                                                                     x.Append(y); return(x); })?.ToString()), readonlyEntries.Contains(keyData.KeyName), stringArrayDefaultValue, stringArrayVanillaValue), alignment);
                        }
                        break;

                    case "KeyCode":
                        string keyCodeValue        = keyData.Value;
                        string keyCodeDefaultValue = defaultValueString;
                        string keyCodeVanillaValue = vanillaValueString;
                        AddComponent(new GadgetConfigKeybindComponent(this, keyData.KeyName, keyCodeValue, (s) => SetConfigValue(section, keyData.KeyName, s), false, readonlyEntries.Contains(keyData.KeyName), keyCodeDefaultValue, keyCodeVanillaValue), alignment);
                        break;

                    default: continue;
                    }
                }
                catch (Exception e)
                {
                    GadgetCore.Log("WARNING: Exception parsing config entry '" + keyData.KeyName + "' with value '" + keyData.Value + "': " + e);
                    try
                    {
                        if (!seperatorMade)
                        {
                            GadgetConfigComponentAlignment?nullableAlignment = AlignConfigEntry(keyData.KeyName);
                            if (nullableAlignment == null)
                            {
                                continue;
                            }
                            alignment = (GadgetConfigComponentAlignment)nullableAlignment;
                            if ((alignment == GadgetConfigComponentAlignment.STANDARD && firstStandard == true) || (alignment == GadgetConfigComponentAlignment.HEADER && firstHeader == true) || (alignment == GadgetConfigComponentAlignment.FOOTER && firstFooter == true))
                            {
                                switch (alignment)
                                {
                                case GadgetConfigComponentAlignment.STANDARD:
                                    firstStandard = false;
                                    break;

                                case GadgetConfigComponentAlignment.HEADER:
                                    firstHeader = false;
                                    break;

                                case GadgetConfigComponentAlignment.FOOTER:
                                    firstFooter = false;
                                    break;
                                }
                            }
                            else
                            {
                                AddComponent(new GadgetConfigSeparatorComponent(this, "Seperator"), alignment);
                            }
                            seperatorMade = true;
                        }
                        if (!commentsMade)
                        {
                            foreach (string comment in keyData.Comments)
                            {
                                if (!string.IsNullOrEmpty(comment) && comment[0] != '[')
                                {
                                    AddComponent(new GadgetConfigLabelComponent(this, "Comment For: " + keyData.KeyName, comment, 0.05f, true), alignment);
                                }
                            }
                            commentsMade = true;
                        }
                        AddComponent(new GadgetConfigSpacerComponent(this, "Parsing Error Spacer for: " + keyData.KeyName));
                        AddComponent(new GadgetConfigLabelComponent(this, "Parsing Error Label for: " + keyData.KeyName, "An error occured parsing the following config entry: " + keyData.KeyName, 0.05f, true), alignment);
                        AddComponent(new GadgetConfigLabelComponent(this, "Parsing Error Label for: " + keyData.KeyName, "As such, a raw-text editor is being provided as a fallback.", 0.05f, true), alignment);
                        AddComponent(new GadgetConfigLabelComponent(this, "Parsing Error Label for: " + keyData.KeyName, "Additionally, the entry's meta-comments are being displayed.", 0.05f, true), alignment);
                        AddComponent(new GadgetConfigSpacerComponent(this, "Parsing Error Spacer for: " + keyData.KeyName));
                        foreach (string comment in keyData.Comments)
                        {
                            if (!string.IsNullOrEmpty(comment) && comment[0] == '[')
                            {
                                AddComponent(new GadgetConfigLabelComponent(this, "Meta-Comment For: " + keyData.KeyName, comment, 0.05f, true), alignment);
                            }
                        }
                        AddComponent(new GadgetConfigStringComponent(this, keyData.KeyName, keyData.Value, (s) => SetConfigValue(section, keyData.KeyName, s), readonlyEntries.Contains(keyData.KeyName)), alignment);
                    }
                    catch (Exception ee)
                    {
                        GadgetCore.Log("WARNING: Failed fallback parsing of config entry '" + keyData.KeyName + "' with value '" + keyData.Value + "': " + ee);
                        try
                        {
                            if (!seperatorMade)
                            {
                                try
                                {
                                    GadgetConfigComponentAlignment?nullableAlignment = AlignConfigEntry(keyData.KeyName);
                                    if (nullableAlignment == null)
                                    {
                                        continue;
                                    }
                                    alignment = (GadgetConfigComponentAlignment)nullableAlignment;
                                    if ((alignment == GadgetConfigComponentAlignment.STANDARD && firstStandard == true) || (alignment == GadgetConfigComponentAlignment.HEADER && firstHeader == true) || (alignment == GadgetConfigComponentAlignment.FOOTER && firstFooter == true))
                                    {
                                        switch (alignment)
                                        {
                                        case GadgetConfigComponentAlignment.STANDARD:
                                            firstStandard = false;
                                            break;

                                        case GadgetConfigComponentAlignment.HEADER:
                                            firstHeader = false;
                                            break;

                                        case GadgetConfigComponentAlignment.FOOTER:
                                            firstFooter = false;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        AddComponent(new GadgetConfigSeparatorComponent(this, "Seperator"), alignment);
                                    }
                                    seperatorMade = true;
                                }
                                catch (Exception se)
                                {
                                    GadgetCore.Log("WARNING: Failed creating seperator for failed config entry '" + keyData.KeyName + "': " + se);
                                }
                            }
                            AddComponent(new GadgetConfigLabelComponent(this, "Fatal Error Name Label for: " + keyData.KeyName, "A FATAL ERROR OCCURED PROCESSING THE FOLLOWING CONFIG ENTRY: " + keyData.KeyName, 0.05f, true), alignment);
                            AddComponent(new GadgetConfigLabelComponent(this, "Fatal Error Value Label for: " + keyData.KeyName, "THE VALUE OF THE CONFIG ENTRY IS: " + keyData.Value, 0.05f, true), alignment);
                        }
                        catch (Exception fe)
                        {
                            GadgetCore.Log("WARNING: Failed creating label for failed config entry '" + keyData.KeyName + "': " + fe);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Unpacks the mod with the specified file path.
 /// </summary>
 public static bool UnpackModFile(string filePath)
 {
     try
     {
         using (ZipFile modZip = ZipFile.Read(filePath))
         {
             if (File.Exists(Path.Combine(UMFData.ModsPath, "ModInfo.txt")))
             {
                 File.Move(Path.Combine(UMFData.ModsPath, "ModInfo.txt"), Path.Combine(UMFData.CachePath, "ModInfoBackup.txt"));
             }
             modZip.ExtractAll(UMFData.ModsPath, ExtractExistingFileAction.OverwriteSilently);
             string dllFile = null;
             foreach (string file in Directory.GetFiles(UMFData.ModsPath, "*.dll"))
             {
                 if (Path.GetFileNameWithoutExtension(filePath).StartsWith(Path.GetFileNameWithoutExtension(file)))
                 {
                     dllFile = file;
                     break;
                 }
             }
             if (dllFile == null)
             {
                 GadgetCore.Log("WARNING! Mod .zip " + Path.GetFileName(filePath) + " is being unpacked, but it does not contain a .dll whos name matches the .zip!");
             }
             if (Directory.Exists(Path.Combine(UMFData.ModsPath, "Tools")))
             {
                 foreach (string file in Directory.GetFiles(Path.Combine(UMFData.ModsPath, "Tools")))
                 {
                     string fileName = Path.Combine(Path.Combine(UMFData.UMFPath, "Tools"), Path.GetFileName(file));
                     if (File.Exists(fileName))
                     {
                         File.Delete(fileName);
                     }
                     File.Move(file, fileName);
                 }
                 Directory.Delete(Path.Combine(UMFData.ModsPath, "Tools"), true);
             }
             if (Directory.Exists(Path.Combine(UMFData.ModsPath, "CoreLibs")) && coreLibInstallerProcess == null)
             {
                 if (Environment.OSVersion.Platform != PlatformID.Win32NT)
                 {
                     ProcessStartInfo coreLibInstallerPI = new ProcessStartInfo
                     {
                         FileName        = "mono",
                         Arguments       = Path.Combine(Path.Combine(UMFData.UMFPath, "Tools"), "GadgetCore.CoreLibInstaller.exe") + " " + Process.GetCurrentProcess().Id,
                         WindowStyle     = ProcessWindowStyle.Hidden,
                         ErrorDialog     = true,
                         UseShellExecute = false,
                     };
                     coreLibInstallerPI.WorkingDirectory = Path.GetDirectoryName(coreLibInstallerPI.FileName);
                     coreLibInstallerProcess             = Process.Start(coreLibInstallerPI);
                 }
                 else
                 {
                     ProcessStartInfo coreLibInstallerPI = new ProcessStartInfo
                     {
                         FileName        = Path.Combine(Path.Combine(UMFData.UMFPath, "Tools"), "GadgetCore.CoreLibInstaller.exe"),
                         Arguments       = Process.GetCurrentProcess().Id.ToString(),
                         WindowStyle     = ProcessWindowStyle.Hidden,
                         ErrorDialog     = true,
                         UseShellExecute = false,
                     };
                     coreLibInstallerPI.WorkingDirectory = Path.GetDirectoryName(coreLibInstallerPI.FileName);
                     coreLibInstallerProcess             = Process.Start(coreLibInstallerPI);
                 }
             }
             if (File.Exists(Path.Combine(UMFData.ModsPath, "ModInfo.txt")))
             {
                 string modInfoName;
                 if (dllFile != null)
                 {
                     string trimmedVersionNumber = FileVersionInfo.GetVersionInfo(dllFile).ToString().Split('.').TakeWhile(x => !x.Equals("0")).Aggregate(new StringBuilder(), (a, b) => { if (a.Length > 0)
                                                                                                                                                                                           {
                                                                                                                                                                                               a.Append(".");
                                                                                                                                                                                           }
                                                                                                                                                                                           a.Append(b); return(a); }).ToString();
                     modInfoName = Path.GetFileNameWithoutExtension(dllFile) + "_v" + FileVersionInfo.GetVersionInfo(dllFile);
                 }
                 else
                 {
                     modInfoName = Path.GetFileNameWithoutExtension(filePath);
                 }
                 if (File.Exists(Path.Combine(UMFData.ModInfosPath, modInfoName + "_ModInfo.txt")))
                 {
                     File.Delete(Path.Combine(UMFData.ModInfosPath, modInfoName + "_ModInfo.txt"));
                 }
                 File.Move(Path.Combine(UMFData.ModsPath, "ModInfo.txt"), Path.Combine(UMFData.ModInfosPath, modInfoName + "_ModInfo.txt"));
             }
             if (File.Exists(Path.Combine(UMFData.CachePath, "ModInfoBackup.txt")))
             {
                 File.Move(Path.Combine(UMFData.CachePath, "ModInfoBackup.txt"), Path.Combine(UMFData.ModsPath, "ModInfo.txt"));
             }
         }
         File.SetAttributes(filePath, FileAttributes.Normal);
         File.Delete(filePath);
         return(true);
     }
     catch (Exception e)
     {
         GadgetCore.Log("Error unpacking mod '" + filePath.Split('\\', '/').Last() + "': " + e.ToString());
         return(false);
     }
 }