Esempio n. 1
0
 public static Patch TryReadPatch(string patchFile, bool activeOnly)
 {
     try
     {
         UserFeedback.Info("Reading the patch file '{0}'", (object)patchFile);
         return(Patcher.ReadPatch(patchFile, activeOnly));
     }
     catch (Exception ex)
     {
         UserFeedback.Error(ex);
         return(new Patch()
         {
             PatchFilepath = patchFile
         });
     }
 }
Esempio n. 2
0
 private static int FindComparablePos(byte[] correctExe, byte[] otherExe, int pos)
 {
     for (int length = 4; length < 25; length += 4)
     {
         byte[] window = new byte[length];
         int    num1   = 0;
         if (num1 + pos < 0)
         {
             num1 = -pos;
         }
         if (num1 + length >= correctExe.Length)
         {
             num1 = correctExe.Length - (pos + length);
         }
         for (int index = 0; index < length; ++index)
         {
             window[index] = correctExe[index + pos + num1];
         }
         int[] array1 = Patcher.FindWindow(otherExe, window).ToArray <int>();
         if (array1.Length == 1)
         {
             return(array1[0] - num1);
         }
         if (array1.Length == 0)
         {
             if (length == 8 && num1 == 0)
             {
                 int num2 = -4;
                 for (int index = 0; index < length; ++index)
                 {
                     window[index] = correctExe[index + pos + num2];
                 }
                 int[] array2 = Patcher.FindWindow(otherExe, window).ToArray <int>();
                 if (array2.Length == 1)
                 {
                     return(array2[0] - num2);
                 }
             }
             UserFeedback.Warning(string.Format("Found no matches for block {0:X8} {1}", (object)pos, (object)length));
             return(-pos);
         }
     }
     UserFeedback.Warning("Found too many matches for block {0:X8}", (object)pos);
     return(-pos);
 }
Esempio n. 3
0
 internal static void Close()
 {
     try
     {
         if (!Application.ExecutablePath.Equals(Console.Title, StringComparison.InvariantCultureIgnoreCase))
         {
             return;
         }
         UserFeedback.Info("Press any key to quit");
         while (!Console.KeyAvailable)
         {
             Thread.Sleep(50);
         }
     }
     catch
     {
     }
 }
Esempio n. 4
0
        public static void PatchResolutions(
            byte[] exe,
            int oldWidth,
            int oldHeight,
            int newWidth,
            int newHeight,
            Patch patch,
            Dictionary <int, int> dictHeigth = null,
            Dictionary <int, int> dictWidth  = null
            )
        {
            Dictionary <int, int> dictionary1 = new Dictionary <int, int>();

            int[] numArray1 = new int[4] {
                800, 1024, 1280, 1600
            };
            if (dictHeigth == null)
            {
                int num1 = newWidth;
                foreach (int index in numArray1)
                {
                    if (index == oldWidth)
                    {
                        dictionary1[index] = newWidth;
                    }
                    else if (index > oldWidth)
                    {
                        dictionary1[index] = ++num1;
                    }
                }
            }
            else
            {
                dictionary1 = dictHeigth;
            }
            Dictionary <int, int> dictionary2 = new Dictionary <int, int>();

            int[] numArray2 = new int[4] {
                600, 768, 1024, 1200
            };
            if (dictWidth == null)
            {
                int num2 = newHeight;
                foreach (int index in numArray2)
                {
                    if (index == oldHeight)
                    {
                        dictionary2[index] = newHeight;
                    }
                    else if (index > oldHeight)
                    {
                        dictionary2[index] = ++num2;
                    }
                }
            }
            else
            {
                dictionary2 = dictWidth;
            }
            foreach (KeyValuePair <int, int> keyValuePair in dictionary1)
            {
                UserFeedback.Trace(string.Format("Horizontal {0} => {1}", (object)keyValuePair.Key, (object)keyValuePair.Value));
            }
            foreach (KeyValuePair <int, int> keyValuePair in dictionary2)
            {
                UserFeedback.Trace(string.Format("Vertical {0} => {1}", (object)keyValuePair.Key, (object)keyValuePair.Value));
            }
            foreach (Item obj in patch.Items)
            {
                if (obj.Pos >= exe.Length)
                {
                    UserFeedback.Warning("Error in input: Invalid location {0:X8}. [NOT PATCHED]", (object)obj.Pos);
                }
                else
                {
                    int  referenceValue = obj.ReferenceValue;
                    bool flag1          = obj.Type.Contains("H");
                    bool flag2          = obj.Type.Contains("V");
                    if (flag1 & flag2)
                    {
                        if (oldWidth == referenceValue)
                        {
                            flag2 = false;
                        }
                        else
                        {
                            flag1 = false;
                        }
                    }
                    Trace.Assert(flag1 | flag2);
                    int num3;
                    if (!(flag2 ? dictionary2 : dictionary1).TryGetValue(referenceValue, out num3))
                    {
                        num3 = referenceValue;
                    }
                    if (obj.Type.Contains("H") && obj.Type.Contains("V"))
                    {
                        UserFeedback.Trace(string.Format("{0} HV: Mapping to {1}", (object)referenceValue, (object)num3));
                    }
                    int num4 = (int)exe[obj.Pos] | (int)exe[obj.Pos + 1] << 8 | (int)exe[obj.Pos + 2] << 16 | (int)exe[obj.Pos + 3] << 24;
                    if (obj.Type.Equals("dV") || obj.Type.Equals("dH"))
                    {
                        int parameter = obj.Parameter;
                        if (parameter == 0)
                        {
                            UserFeedback.Warning(string.Format("{0} action is safer if you mention the expected orgValue. Encountered {1} @ {2:X8}", (object)obj.Type, (object)num4, (object)obj.Pos));
                        }
                        else if (parameter != num4)
                        {
                            UserFeedback.Warning(string.Format("{0} action expected value mismatch: {1} expected, {2} encountered @ {3:X8} [NOT PATCHED]", (object)obj.Type, (object)parameter, (object)num4, (object)obj.Pos));
                            continue;
                        }
                        int num5 = num3 - referenceValue;
                        num3 = num4 + num5;
                    }
                    else if (num4 != referenceValue)
                    {
                        UserFeedback.Warning(string.Format("{0} action expected value mismatch: {1} expected, {2} encountered @ {3:X8} [NOT PATCHED]", (object)obj.Type, (object)referenceValue, (object)num4, (object)obj.Pos));
                        continue;
                    }
                    byte num6 = (byte)(num3 & (int)byte.MaxValue);
                    byte num7 = (byte)(num3 >> 8 & (int)byte.MaxValue);
                    byte num8 = (byte)(num3 >> 16 & (int)byte.MaxValue);
                    byte num9 = (byte)(num3 >> 24 & (int)byte.MaxValue);
                    exe[obj.Pos]     = num6;
                    exe[obj.Pos + 1] = num7;
                    exe[obj.Pos + 2] = num8;
                    exe[obj.Pos + 3] = num9;
                }
            }
        }
Esempio n. 5
0
 public static void Warning(string msg, object param1)
 {
     UserFeedback.Warning(string.Format(msg, param1));
 }
Esempio n. 6
0
 public static void Trace(string msg, object param1)
 {
     UserFeedback.Trace(string.Format(msg, param1));
 }
Esempio n. 7
0
 public static void Info(string msg, object param1)
 {
     UserFeedback.Info(string.Format(msg, param1));
 }
Esempio n. 8
0
        public static byte[] UpdateGuiTable(
            byte[] data,
            uint id,
            int oldWidth,
            int oldHeight,
            int newWidth,
            int newHeight)
        {
            int index1;
            int index2;
            int index3;
            int index4;

            switch (oldWidth)
            {
            case 800:
                index1 = 1;
                index2 = 2;
                index3 = 3;
                index4 = 4;
                break;

            case 1024:
                index1 = 5;
                index2 = 6;
                index3 = 7;
                index4 = 8;
                break;

            case 1280:
                index1 = 9;
                index2 = 10;
                index3 = 11;
                index4 = 12;
                break;

            default:
                return(data);
            }
            int num1 = newHeight - oldHeight;
            int num2 = newWidth - oldWidth;

            if (data.Length < 10)
            {
                return(data);
            }
            try
            {
                string str = Encoding.ASCII.GetString(data, 0, 10);
                if (str == null || !str.Equals("Item Name\t"))
                {
                    return(data);
                }
            }
            catch
            {
                return(data);
            }
            try
            {
                string[][] array = ((IEnumerable <string>)Encoding.ASCII.GetString(data).Split(new char[2]
                {
                    '\r',
                    '\n'
                }, StringSplitOptions.RemoveEmptyEntries)).Select <string, string[]>((Func <string, string[]>)(line => line.Split('\t'))).ToArray <string[]>();
                foreach (string[] strArray in array)
                {
                    if (strArray.Length >= 13 && !string.IsNullOrEmpty(strArray[0]) && !string.IsNullOrEmpty(strArray[12]))
                    {
                        int num3 = int.Parse(strArray[index1]);
                        int num4 = int.Parse(strArray[index2]);
                        int num5 = int.Parse(strArray[index3]);
                        int num6 = int.Parse(strArray[index4]);
                        if (num4 < oldHeight / 2 && num4 + num6 > oldHeight / 2)
                        {
                            num6 += num1;
                        }
                        else if (num4 > oldHeight / 2)
                        {
                            num4 += num1;
                        }
                        if (num5 == oldWidth)
                        {
                            num5 = newWidth;
                        }
                        strArray[index1] = num3.ToString();
                        strArray[index2] = num4.ToString();
                        strArray[index3] = num5.ToString();
                        strArray[index4] = num6.ToString();
                    }
                }
                byte[] bytes = Encoding.ASCII.GetBytes(((IEnumerable <string[]>)array).Select <string[], string>((Func <string[], string>)(tableRow => ((IEnumerable <string>)tableRow).Aggregate <string>((Func <string, string, string>)((output, col) => output + "\t" + col)))).Aggregate <string>((Func <string, string, string>)((output, line) => output + "\r\n" + line)));
                UserFeedback.Info("Patched Gui Table #{0}", (object)id);
                return(bytes);
            }
            catch (Exception ex)
            {
                UserFeedback.Warning("Failed to patch Gui Table #{0}; leaving it unchanged.", (object)id);
                UserFeedback.Error(ex);
                return(data);
            }
        }
Esempio n. 9
0
        public static byte[] Enlarge(uint id, byte[] data, int oldWidth, int oldHeight, int newWidth, int newHeight)
        {
            var reader     = new BinaryReader(new MemoryStream(data, false));
            var duplicated = new byte[newWidth];
            var version    = reader.ReadUInt32();

            if (version != 0x4e302e32)
            {
                return(data);
            }

            var framecount = reader.ReadUInt32();

            if (framecount != 1)
            {
                return(data);
            }
            if (oldWidth == newWidth)
            {
                return(data);
            }
            var comment       = reader.ReadBytes(24);
            var linesOffset   = reader.ReadUInt32();
            var maskOffset    = reader.ReadUInt32();
            var paletteOffset = reader.ReadUInt32();
            var properties    = reader.ReadUInt32();

            var width = reader.ReadInt32();

            if (width != oldWidth)
            {
                return(data);
            }

            var height  = reader.ReadInt32();
            var centerX = reader.ReadInt32();
            var centerY = reader.ReadInt32();

            if (height - centerY != oldHeight)//!=
            {
                return(data);
            }

            if (centerY != 0)
            {
                int higher = newHeight - oldHeight;
                centerY  -= higher;
                newHeight = oldHeight = height;
            }

            var newMaskSize      = (uint)(newHeight * 4);
            var newLinesOffset   = maskOffset + newMaskSize;
            var newLinesSize     = (uint)(newHeight * 4);
            var newLineDataStart = newLinesOffset + newLinesSize;

            var outStream = new MemoryStream();
            var writer    = new BinaryWriter(outStream);

            try
            {
                UserFeedback.Info(string.Format("Resizing image #{0} for {1}x{2} to {3}x{4}",
                                                id, oldWidth, oldHeight, newWidth, newHeight));

                writer.Write(version);
                writer.Write(framecount);
                writer.Write(comment);
                writer.Write(newLinesOffset);
                writer.Write(maskOffset);
                writer.Write(paletteOffset);
                writer.Write(properties);
                writer.Write(newWidth);
                writer.Write(newHeight);
                writer.Write(centerX);
                writer.Write(centerY);

                var osp = outStream.Position;
                Trace.Assert(osp == maskOffset);

                var orgLineMasks = new UInt32[oldHeight];
                for (var inLine = 0; inLine < oldHeight; inLine++)
                {
                    orgLineMasks[inLine] = reader.ReadUInt32();
                }

                var orgLineStarts = new UInt32[oldHeight + 1];
                for (var inLine = 0; inLine < oldHeight; inLine++)
                {
                    orgLineStarts[inLine] = reader.ReadUInt32();
                }
                orgLineStarts[oldHeight] = (uint)data.Length;

                var orgLines = new List <byte[]>(oldHeight);
                for (var inLine = 0; inLine < oldHeight; inLine++)
                {
                    var orgLineSize = orgLineStarts[inLine + 1] - orgLineStarts[inLine];
                    orgLines.Add(reader.ReadBytes((int)orgLineSize));
                }

                var newLineMasks = new UInt32[newHeight];
                var newLines     = new List <byte[]>(newHeight);

                var extraLines = newHeight - oldHeight;
                var shrinking  = extraLines < 0;
                var expanding  = extraLines > 0;

                var centreLine = oldHeight / 2;

                var shrinkSkipStart = centreLine + extraLines;
                var shrinkSkipEnd   = centreLine;

                // duplication is the amount of times every duplicated line, is duplicated
                var duplication = 1 + (extraLines + 1) / (oldHeight / 2);
                // the duplication block size is the block that is being duplicated
                // the last line of which MIGHT not be duplicated 'duplication' times
                //  eg if duplication is 2, extralines = 501, dbs = 251, the last of which is
                //  duped just once.
                var duplicationBlockSize = (extraLines + duplication - 1) / duplication;

                var dupStart   = centreLine - duplicationBlockSize / 2;
                var dupEnd     = dupStart + duplicationBlockSize;
                var newlineold = new byte[newWidth];
                var dupedLines = 0; //'UNIT'TEST
                for (var inLine = 0; inLine < oldHeight; inLine++)
                {
                    // If shrinking skip 'extralines' lines on the centerline and above
                    if (shrinking && inLine >= shrinkSkipStart && inLine < shrinkSkipEnd)
                    {
                        dupedLines--;
                        continue;
                    }

                    newLineMasks[newLines.Count] = orgLineMasks[inLine];

                    var newLine = StretchLine(orgLines[inLine], oldWidth, newWidth);

                    newLineMasks[newLines.Count] = orgLineMasks[inLine];

                    newLines.Add(newLine);
                    // If expanding, duplicate the right amount of lines before centreLine
                    if (!expanding || inLine < dupStart || inLine >= dupEnd)
                    {
                        continue;
                    }

                    for (var rep = 0; rep < duplication && dupedLines < extraLines; rep++)
                    {
                        newLines.Add(newLine);
                        dupedLines++;
                    }
                }
                Trace.Assert(newLines.Count == newHeight);
                Trace.Assert(dupedLines == extraLines);

                var nextLineStart = newLineDataStart;

                foreach (var newLineMask in newLineMasks)
                {
                    writer.Write(newLineMask);
                }

                osp = outStream.Position;
                Trace.Assert(newLinesOffset == osp);

                foreach (var newLine in newLines)
                {
                    writer.Write(nextLineStart);
                    nextLineStart += (uint)newLine.Length;
                }

                osp = outStream.Position;
                Trace.Assert(newLineDataStart == osp);

                foreach (var newLine in newLines)
                {
                    writer.Write(newLine);
                }

                Trace.Assert(outStream.Position == nextLineStart);

                writer.Close();
            }
            catch (Exception ex)
            {
            }

            var newSlp = outStream.ToArray();

            //outStream.ToArray();



            //2077858 mirror
            return(newSlp);
        }