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); }
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; } } }
public static void Warning(string msg, object param1) { UserFeedback.Warning(string.Format(msg, param1)); }
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); } }