public static MidsCharacterFileFormat.eLoadReturnCode MxDExtractAndLoad(
        Stream iStream)
    {
        StreamReader streamReader;

        try
        {
            streamReader = new StreamReader(iStream);
            streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
        }
        catch (Exception ex)
        {
            int num = (int)MessageBox.Show("Unable to read data - " + ex.Message, "ExtractAndLoad Failed");
            return(MidsCharacterFileFormat.eLoadReturnCode.Failure);
        }
        string[] strArray1 = new string[4]
        {
            "ABCD",
            "0",
            "0",
            "0"
        };
        string a = "";

        MidsCharacterFileFormat.eLoadReturnCode eLoadReturnCode;
        try
        {
            string str = streamReader.ReadToEnd().Replace("||", "|\n|");
            streamReader.Close();
            string[] strArray2 = str.Split('\n');
            int      num1      = -1;
            if (strArray2.Length < 1)
            {
                int num2 = (int)MessageBox.Show("Unable to locate data header - Zero-Length Input!", "ExtractAndLoad Failed");
                eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
            }
            else
            {
                for (int index = 0; index < strArray2.Length; ++index)
                {
                    int startIndex = strArray2[index].IndexOf(MagicUncompressed, StringComparison.Ordinal);
                    if (startIndex < 0)
                    {
                        startIndex = strArray2[index].IndexOf(MagicCompressed, StringComparison.Ordinal);
                    }
                    if (startIndex < 0)
                    {
                        startIndex = strArray2[index].IndexOf("MHDz", StringComparison.OrdinalIgnoreCase);
                    }
                    if (startIndex > -1)
                    {
                        strArray1 = strArray2[index].Substring(startIndex).Split(';');
                        a         = strArray1.Length > 0 ? strArray1[0] : string.Empty;
                        num1      = index;
                        break;
                    }
                }
                if (num1 < 0)
                {
                    int num2 = (int)MessageBox.Show("Unable to locate data header - Magic Number not found!", "ExtractAndLoad Failed");
                    eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
                }
                else if (string.Equals(a, "MHDz", StringComparison.OrdinalIgnoreCase))
                {
                    eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.IsOldFormat;
                }
                else if (num1 + 1 == strArray2.Length)
                {
                    int num2 = (int)MessageBox.Show("Unable to locate data - Nothing beyond header!", "ExtractAndLoad Failed");
                    eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
                }
                else
                {
                    string iString = string.Empty;
                    for (int index = num1 + 1; index <= strArray2.Length - 1; ++index)
                    {
                        iString = iString + strArray2[index] + "\n";
                    }
                    int  int32_1 = Convert.ToInt32(strArray1[1]);
                    int  int32_2 = Convert.ToInt32(strArray1[2]);
                    int  int32_3 = Convert.ToInt32(strArray1[3]);
                    bool isHex   = false;
                    if (strArray1.Length > 4)
                    {
                        isHex = string.Equals(strArray1[4], "HEX", StringComparison.OrdinalIgnoreCase);
                    }
                    byte[] iBytes = new ASCIIEncoding().GetBytes(isHex ? Zlib.UnbreakHex(iString) : Zlib.UnbreakString(iString, true));
                    streamReader.Close();
                    if (iBytes.Length < int32_3)
                    {
                        int num2 = (int)MessageBox.Show("Data chunk was incomplete! Check that the entire chunk was copied to the clipboard.", "ExtractAndLoad Failed");
                        eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
                    }
                    else
                    {
                        if (iBytes.Length > int32_3)
                        {
                            Array.Resize <byte>(ref iBytes, int32_3);
                        }
                        iBytes = isHex ? Zlib.HexDecodeBytes(iBytes) : Zlib.UUDecodeBytes(iBytes);
                        if (iBytes.Length == 0)
                        {
                            eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
                        }
                        else
                        {
                            if (a == MagicCompressed)
                            {
                                Array.Resize <byte>(ref iBytes, int32_2);
                                byte[] tempByteArray = iBytes; // Pine
                                iBytes = Zlib.UncompressChunk(ref tempByteArray, int32_1);
                            }
                            eLoadReturnCode = iBytes.Length != 0 ? (MidsCharacterFileFormat.MxDReadSaveData(ref iBytes, false) ? MidsCharacterFileFormat.eLoadReturnCode.Success : MidsCharacterFileFormat.eLoadReturnCode.Failure) : MidsCharacterFileFormat.eLoadReturnCode.Failure;
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("Unable to read data - " + ex.Message, "ExtractAndLoad Failed");
            streamReader?.Close();
            eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
        }
        return(eLoadReturnCode);
    }
    public static MidsCharacterFileFormat.eLoadReturnCode MxDExtractAndLoad(Stream iStream)
    {
        StreamReader streamReader;

        MidsCharacterFileFormat.eLoadReturnCode eLoadReturnCode;
        try
        {
            streamReader = new StreamReader(iStream);
            streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Unable to read data - " + ex.Message, "ExtractAndLoad Failed");
            eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
            return(eLoadReturnCode);
        }
        string[] strArray = new string[]
        {
            "ABCD",
            "0",
            "0",
            "0"
        };
        string a = "";

        try
        {
            string str = streamReader.ReadToEnd().Replace("||", "|\n|");
            streamReader.Close();
            string[] strArray2 = str.Split(new char[]
            {
                '\n'
            });
            int num = -1;
            if (strArray2.Length < 1)
            {
                MessageBox.Show("Unable to locate data header - Zero-Length Input!", "ExtractAndLoad Failed");
                eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
            }
            else
            {
                for (int index = 0; index < strArray2.Length; index++)
                {
                    int startIndex = strArray2[index].IndexOf("MxDu", StringComparison.Ordinal);
                    if (startIndex < 0)
                    {
                        startIndex = strArray2[index].IndexOf("MxDz", StringComparison.Ordinal);
                    }
                    if (startIndex < 0)
                    {
                        startIndex = strArray2[index].IndexOf("MHDz", StringComparison.OrdinalIgnoreCase);
                    }
                    if (startIndex > -1)
                    {
                        strArray = strArray2[index].Substring(startIndex).Split(new char[]
                        {
                            ';'
                        });
                        a   = ((strArray.Length > 0) ? strArray[0] : string.Empty);
                        num = index;
                        break;
                    }
                }
                if (num < 0)
                {
                    MessageBox.Show("Unable to locate data header - Magic Number not found!", "ExtractAndLoad Failed");
                    eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
                }
                else if (string.Equals(a, "MHDz", StringComparison.OrdinalIgnoreCase))
                {
                    eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.IsOldFormat;
                }
                else if (num + 1 == strArray2.Length)
                {
                    MessageBox.Show("Unable to locate data - Nothing beyond header!", "ExtractAndLoad Failed");
                    eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
                }
                else
                {
                    string iString = string.Empty;
                    for (int index2 = num + 1; index2 <= strArray2.Length - 1; index2++)
                    {
                        iString = iString + strArray2[index2] + "\n";
                    }
                    int  int32_  = Convert.ToInt32(strArray[1]);
                    int  int32_2 = Convert.ToInt32(strArray[2]);
                    int  int32_3 = Convert.ToInt32(strArray[3]);
                    bool flag    = false;
                    if (strArray.Length > 4)
                    {
                        flag = string.Equals(strArray[4], "HEX", StringComparison.OrdinalIgnoreCase);
                    }
                    ASCIIEncoding asciiencoding = new ASCIIEncoding();
                    byte[]        iBytes        = asciiencoding.GetBytes(flag ? Zlib.UnbreakHex(iString) : Zlib.UnbreakString(iString, true));
                    streamReader.Close();
                    if (iBytes.Length < int32_3)
                    {
                        MessageBox.Show("Data chunk was incomplete! Check that the entire chunk was copied to the clipboard.", "ExtractAndLoad Failed");
                        eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
                    }
                    else
                    {
                        if (iBytes.Length > int32_3)
                        {
                            Array.Resize <byte>(ref iBytes, int32_3);
                        }
                        iBytes = (flag ? Zlib.HexDecodeBytes(iBytes) : Zlib.UUDecodeBytes(iBytes));
                        if (iBytes.Length == 0)
                        {
                            eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
                        }
                        else
                        {
                            if (a == "MxDz")
                            {
                                Array.Resize <byte>(ref iBytes, int32_2);
                                iBytes = Zlib.UncompressChunk(ref iBytes, int32_);
                            }
                            if (iBytes.Length == 0)
                            {
                                eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
                            }
                            else if (!MidsCharacterFileFormat.MxDReadSaveData(ref iBytes, false))
                            {
                                eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
                            }
                            else
                            {
                                eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Success;
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex2)
        {
            MessageBox.Show("Unable to read data - " + ex2.Message, "ExtractAndLoad Failed");
            if (streamReader != null)
            {
                streamReader.Close();
            }
            eLoadReturnCode = MidsCharacterFileFormat.eLoadReturnCode.Failure;
        }
        return(eLoadReturnCode);
    }