ShowErrorMessage() public static method

Displays an error message.
public static ShowErrorMessage ( string err ) : void
err string
return void
コード例 #1
0
ファイル: IL.cs プロジェクト: skulltraill/TerrariaPatcher
        /// <summary>
        /// Only use this instead of GetTypeDefinition() when the type is not within the Terraria module (eg. an XNA type).
        /// </summary>
        /// <param name="fullName"></param>
        /// <returns></returns>
        public static TypeReference GetTypeReference(ModuleDefinition moduleDefinition, string fullName, bool verbose = true)
        {
            TypeReference reference;

            if (!moduleDefinition.TryGetTypeReference(fullName, out reference) && verbose)
            {
                Program.ShowErrorMessage(string.Format("Failed to locate {0} type!", fullName));
            }

            return(reference);
        }
コード例 #2
0
ファイル: IL.cs プロジェクト: skulltraill/TerrariaPatcher
        /// <summary>
        /// Returns a method definition.
        /// </summary>
        /// <param name="t"></param>
        /// <param name="methodName"></param>
        /// <returns></returns>
        public static ModuleDefinition GetModuleDefinition(AssemblyDefinition definition, string fullyQualifiedName, bool verbose = true)
        {
            ModuleDefinition module = definition.Modules.FirstOrDefault(p => p.FullyQualifiedName == fullyQualifiedName);

            if (module == null && verbose)
            {
                Program.ShowErrorMessage(string.Format("Failed to locate {0} reference!", fullyQualifiedName));
                module = definition.MainModule;
            }

            return(module);
        }
コード例 #3
0
ファイル: IL.cs プロジェクト: skulltraill/TerrariaPatcher
        /// <summary>
        /// Returns a type definition.
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public static TypeDefinition GetTypeDefinition(ModuleDefinition moduleDefinition, string typeName, bool verbose = true)
        {
            var result = (from TypeDefinition t in moduleDefinition.Types
                          where t.Name == typeName
                          select t).FirstOrDefault();

            if (result == null && verbose)
            {
                Program.ShowErrorMessage(string.Format("Failed to locate {0} type!", typeName));
            }

            return(result);
        }
コード例 #4
0
ファイル: IL.cs プロジェクト: skulltraill/TerrariaPatcher
        /// <summary>
        /// Returns a property definition.
        /// </summary>
        /// <param name="t"></param>
        /// <param name="propName"></param>
        /// <returns></returns>
        public static PropertyDefinition GetPropertyDefinition(TypeDefinition t, string propName, bool verbose = true)
        {
            var result = (from PropertyDefinition p in t.Properties
                          where p.Name == propName
                          select p).FirstOrDefault();

            if (result == null && verbose)
            {
                Program.ShowErrorMessage(string.Format("Failed to locate {0}.{1} property!", t.FullName, propName));
            }

            return(result);
        }
コード例 #5
0
ファイル: IL.cs プロジェクト: skulltraill/TerrariaPatcher
        /// <summary>
        /// Returns a method definition.
        /// </summary>
        /// <param name="t"></param>
        /// <param name="methodName"></param>
        /// <returns></returns>
        public static MethodDefinition GetMethodDefinition(TypeDefinition t, string methodName, int parameterCount = -1, bool verbose = true)
        {
            var result = (from MethodDefinition m in t.Methods
                          where m.Name == methodName && (parameterCount == -1 || m.Parameters.Count + m.GenericParameters.Count == parameterCount)
                          select m).FirstOrDefault();

            if (result == null && verbose)
            {
                Program.ShowErrorMessage(string.Format("Failed to locate {0}.{1}() method!", t.FullName, methodName));
            }

            return(result);
        }
コード例 #6
0
ファイル: IL.cs プロジェクト: skulltraill/TerrariaPatcher
        /// <summary>
        /// Returns a property definition.
        /// </summary>
        /// <param name="t"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public static FieldDefinition GetFieldDefinition(TypeDefinition t, string fieldName, bool verbose = true)
        {
            var result = (from FieldDefinition f in t.Fields
                          where f.Name == fieldName
                          select f).FirstOrDefault();

            if (result == null && verbose)
            {
                Program.ShowErrorMessage(string.Format("Failed to locate {0}.{1} field!", t.FullName, fieldName));
            }

            return(result);
        }
コード例 #7
0
ファイル: IL.cs プロジェクト: skulltraill/TerrariaPatcher
        public static FieldDefinition AddStaticField(TypeDefinition classType, string field, TypeReference type, object value = null)
        {
            var classStaticConstructor = GetMethodDefinition(classType, ".cctor");

            if (classStaticConstructor == null)
            {
                return(null);
            }

            var fld = new FieldDefinition(field, FieldAttributes.Static | FieldAttributes.Public, type);

            classType.Fields.Add(fld);

            if (value != null)
            {
                var il    = classStaticConstructor.Body.GetILProcessor();
                var first = il.Body.Instructions[0];

                if (type.Name == "String")
                {
                    il.InsertBefore(first, il.Create(OpCodes.Ldstr, (string)value));
                }
                else if (type.Name == "Int32")
                {
                    il.InsertBefore(first, il.Create(OpCodes.Ldc_I4, (int)value));
                }
                else if (type.Name == "Boolean")
                {
                    il.InsertBefore(first, il.Create(OpCodes.Ldc_I4, (bool)value ? 1 : 0));
                }
                else if (type.Name == "Single")
                {
                    il.InsertBefore(first, il.Create(OpCodes.Ldc_R4, (Single)value));
                }
                else if (value is Instruction)
                {
                    il.InsertBefore(first, (Instruction)value);
                }
                else
                {
                    Program.ShowErrorMessage(string.Format("AddStaticField(): Unrecognized type '{0}'!", type.FullName));
                }

                il.InsertBefore(first, il.Create(OpCodes.Stsfld, fld));
            }

            return(fld);
        }
コード例 #8
0
ファイル: IL.cs プロジェクト: skulltraill/TerrariaPatcher
        public static void ModifyStaticField(TypeDefinition classType, string field, object newValue)
        {
            var classStaticConstructor = GetMethodDefinition(classType, ".cctor");

            if (classStaticConstructor == null)
            {
                return;
            }

            if (newValue is string)
            {
                ModifyStaticField(classStaticConstructor, field, instr =>
                {
                    instr.OpCode  = OpCodes.Ldstr;
                    instr.Operand = newValue;
                });
            }
            else if (newValue is int || newValue is bool)
            {
                ModifyStaticField(classStaticConstructor, field, instr =>
                {
                    instr.OpCode  = OpCodes.Ldc_I4;
                    instr.Operand = newValue;
                });
            }
            else if (newValue is float)
            {
                ModifyStaticField(classStaticConstructor, field, instr =>
                {
                    instr.OpCode  = OpCodes.Ldc_R4;
                    instr.Operand = newValue;
                });
            }
            else
            {
                Program.ShowErrorMessage(string.Format("ModifyStaticField(): Unrecognized type '{0}'!", newValue.GetType().FullName));
            }
        }
コード例 #9
0
ファイル: Main.cs プロジェクト: xT10r/TerrariaPatcher
        private void save_Click(object sender, EventArgs e)
        {
            if (!File.Exists(terrariaPath.Text))
            {
                MessageBox.Show("Terraria path needs to point at a valid executable.", Program.AssemblyName + " :: Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!Utils.IsProcessElevated && plugins.Checked && !steamFixEnabled.Checked)
            {
                MessageBox.Show("Warning, your account does not have elevated administrator privileges. After patching, you might need to run Steam with elevated administrator privileges before running Terraria.", Program.AssemblyName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            CheckInstallationFolder();

            saveFileDialog.InitialDirectory = Path.GetDirectoryName(terrariaPath.Text);
            saveFileDialog.FileName         = "Terraria.exe";

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                var original = terrariaPath.Text;

                if (File.Exists(saveFileDialog.FileName + ".bak"))
                {
                    var warning = "";
                    try
                    {
                        var versionCurrent = IL.GetAssemblyVersion(saveFileDialog.FileName);
                        var versionBackup  = IL.GetAssemblyVersion(saveFileDialog.FileName + ".bak");
                        if (versionCurrent != versionBackup)
                        {
                            warning = Environment.NewLine + Environment.NewLine + "WARNING: Your Terraria.exe is version " + versionCurrent + " and your Terraria.exe.bak is version " + versionBackup +
                                      ".";
                            if (versionCurrent > versionBackup)
                            {
                                warning += " It is not recommended to restore a backup of an older version of Terraria!";
                            }
                        }
                    }
                    catch
                    { }

                    if (MessageBox.Show("Would you like to restore your backup before patching?" + warning, Program.AssemblyName, MessageBoxButtons.YesNo, string.IsNullOrEmpty(warning) ? MessageBoxIcon.Question : MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        File.Delete(saveFileDialog.FileName);
                        File.Move(saveFileDialog.FileName + ".bak", saveFileDialog.FileName);
                    }
                }

                if (File.Exists(saveFileDialog.FileName))
                {
                    if (MessageBox.Show("Would you like to backup the existing file?", Program.AssemblyName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        File.Copy(saveFileDialog.FileName, saveFileDialog.FileName + ".bak", true);
                    }
                }

                var buffValues = (from Buff buff in buffs.Where(buff => buff.Active) select buff.Index).ToList();
                var details    = new TerrariaDetails()
                {
                    InfiniteCloudJumps     = infiniteCloudJumps.Checked,
                    FunctionalSocialSlots  = functionalSocialSlots.Checked,
                    VampiricHealing        = (float)vampiricKnivesHealingRate.Value,
                    SpectreHealing         = (float)spectreHealingRate.Value,
                    FixedPrefixes          = fixedPrefixes.Checked,
                    AccessoryPrefix        = SetAccessoryPrefixValue(),
                    DisplayTime            = timeEnabled.Checked,
                    PermanentBuffs         = buffValues,
                    PermanentWings         = permanentWings.Enabled && permanentWings.Checked,
                    OneHitKill             = oneHitKill.Checked,
                    InfiniteAmmo           = infiniteAmmo.Checked,
                    RemoveDrowning         = removeDrowning.Checked,
                    RemoveDiscordBuff      = removeRodBuffEnabled.Checked,
                    RemoveManaCost         = removeManaCosts.Checked,
                    RemovePotionSickness   = removePotionSickness.Checked,
                    RemoveAnglerQuestLimit = removeAnglerQuestLimit.Checked,
                    MaxCraftingRange       = maxCraftingRange.Checked,
                    SpawnRateVoodoo        = (int)spawnRateVoodoo.Value,
                    SteamFix = steamFixEnabled.Enabled && steamFixEnabled.Checked,
                    Plugins  = plugins.Checked,
                };
                try
                {
                    Terraria.Patch(original, saveFileDialog.FileName, details);

                    if (details.Plugins)
                    {
                        var targetFolder = Path.GetDirectoryName(saveFileDialog.FileName);
                        foreach (var t in new[] { "PluginLoader.XNA.dll", "PluginLoader.FNA.dll" })
                        {
                            var target = $"{targetFolder}\\{t}";

                            var pluginLoaderInfo = new FileInfo(target);
                            while (Utils.IsFileLocked(pluginLoaderInfo))
                            {
                                var result = MessageBox.Show(target + " is in use. Please close Terraria then hit OK.", Program.AssemblyName, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                                if (result == DialogResult.Cancel)
                                {
                                    return;
                                }
                            }

                            File.Copy(t, target, true);
                        }

                        if (!Directory.Exists(@".\Plugins"))
                        {
                            MessageBox.Show("Plugins folder is missing from TerrariaPatcher folder. Please re-download.", Program.AssemblyName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (!Directory.Exists(@".\Plugins\Shared"))
                        {
                            MessageBox.Show(@"Plugins\Shared folder is missing from TerrariaPatcher folder. Please re-download.", Program.AssemblyName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else
                        {
                            new CopyPlugins(targetFolder).ShowDialog();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Program.ShowErrorMessage("An error occurred, you possibly have already patched this exe or it is an incompatible version.\n\n" + ex.ToString());
                }

                MessageBox.Show("Done.", Program.AssemblyName);
            }
        }