private static IntPtr ParseField(FieldInfo field, PatternFinder pf) { var offset = (OffsetAttribute)Attribute.GetCustomAttributes(field, typeof(OffsetAttribute)) .FirstOrDefault(); var valcn = (OffsetValueCN)Attribute.GetCustomAttributes(field, typeof(OffsetValueCN)) .FirstOrDefault(); var valna = (OffsetValueNA)Attribute.GetCustomAttributes(field, typeof(OffsetValueNA)) .FirstOrDefault(); var result = IntPtr.Zero; var lang = (Language)typeof(DataManager).GetFields(BindingFlags.Static | BindingFlags.NonPublic) .First(i => i.FieldType == typeof(Language)).GetValue(null); if (lang == Language.Chn) { if (valcn != null) { return((IntPtr)valcn.Value); } if (offset == null) { return(IntPtr.Zero); } var b1 = true; var results = pf.FindMany(offset.PatternCN, ref b1); if (results != null) { result = results[0]; } } else { if (valna != null) { return((IntPtr)valna.Value); } if (offset == null) { return(IntPtr.Zero); } var b1 = true; var results = pf.FindMany(offset.Pattern, ref b1); if (results != null) { result = results[0]; } } Log($"[{field.Name:,27}] {result.ToInt64():X}"); return(result); }
private static IntPtr ParseField(FieldInfo field, PatternFinder pf) { OffsetAttribute offset = (OffsetAttribute)Attribute.GetCustomAttributes(field, typeof(OffsetAttribute)) .FirstOrDefault(); OffsetValueCN valcn = (OffsetValueCN)Attribute.GetCustomAttributes(field, typeof(OffsetValueCN)) .FirstOrDefault(); OffsetValueNA valna = (OffsetValueNA)Attribute.GetCustomAttributes(field, typeof(OffsetValueNA)) .FirstOrDefault(); IntPtr result = IntPtr.Zero; if (Constants.Lang == Language.Chn) { if (valcn != null) { return((IntPtr)valcn.Value); } if (offset == null) { return(IntPtr.Zero); } bool b1 = true; IntPtr[] results = pf.FindMany(offset.PatternCN, ref b1); if (results != null) { result = results[0]; } } else { if (valna != null) { return((IntPtr)valna.Value); } if (offset == null) { return(IntPtr.Zero); } bool b1 = true; IntPtr[] results = pf.FindMany(offset.Pattern, ref b1); if (results != null) { result = results[0]; } } Logger.Info("[OffsetManager][{0:,27}] {1}", field.Name, result.ToString("X")); return(result); }
public static void IntalizeOffsets() { if (SecondaryOffsetManager.Initalized) { return; } Rebase = Core.Memory.Process.MainModule.BaseAddress; //The namespace specified should only be containers for offsets var types = Assembly.GetExecutingAssembly() .GetTypes() .Where(t => t.Namespace == "ExBuddy.Offsets" && t.IsClass) .OrderBy(t => t.Name) .ToArray(); Parallel.ForEach( types, type => { var pf = new PatternFinder(Core.Memory); foreach (var info in type.GetFields()) { #if RB_X64 var offset = (Offset64)Attribute.GetCustomAttributes(info, typeof(Offset64)).FirstOrDefault(); #else var offset = (Offset) Attribute.GetCustomAttributes(info, typeof (Offset)).FirstOrDefault(r => r.GetType() != typeof (OffsetCN)); #if RB_CN var tmp = (Offset)Attribute.GetCustomAttribute(info, typeof(OffsetCN)); if (tmp != null) { offset = tmp; } #endif #endif if (offset == null) { continue; } try { var markedDontRebase = false; var pattern = offset.Pattern; if (!pattern.Trim().EndsWith("DontRebase")) { pattern = pattern + " DontRebase"; } var results = pf.FindMany(pattern, ref markedDontRebase); if (results == null) { //Failed to find a pattern match. logr.Write("No match for {0} some functionality may not work correctly", info.Name); continue; } if (results.Length > 1) { lock (Core.Memory) { if (offset.MultipleResults) { if (results.Distinct().Count() == 1) { //Multiple matches were expected but there was only one result, double check that our pattern is still finding what we wanted logr.Write( "Multiple matches for {0} were expected, but only one result was found, some functionality may not work correctly", info.Name); } } else { //Multiple matches to the provided pattern were found and we were not expecting this logr.Write( "Multiple matches for {0} which was not expected, some functionality may not work correctly", info.Name); } } } #if RB_X64 var addrz = (long)results[0]; if (offset.Modifier != 0) { addrz = (long)(addrz + offset.Modifier); } logr.Write("[SecondaryOffsetManager] Found 0x{0:X} for {1}", addrz, info.Name); if (info.FieldType == typeof(IntPtr)) { info.SetValue(null, (IntPtr)addrz); } else { info.SetValue(null, (int)addrz); } #else var addrz = (uint) results[0]; if (offset.Modifier != 0) { addrz = (uint) (addrz + offset.Modifier); } logr.Write("[SecondaryOffsetManager] Found 0x{0:X} for {1}", addrz, info.Name); if (info.FieldType == typeof (IntPtr)) { info.SetValue(null, (IntPtr) addrz); } else { info.SetValue(null, (int) addrz); } #endif } catch (Exception e) { //Something went wrong logr.WriteException(e); } } }); SecondaryOffsetManager.Initalized = true; }
public static void IntalizeOffsets() { if (SecondaryOffsetManager.Initalized) { return; } Rebase = Core.Memory.Process.MainModule.BaseAddress; //The namespace specified should only be containers for offsets var types = Assembly.GetExecutingAssembly() .GetTypes() .Where(t => t.Namespace == "ExBuddy.Offsets" && t.IsClass) .OrderBy(t => t.Name) .ToArray(); Parallel.ForEach( types, type => { var pf = new PatternFinder(Core.Memory); foreach (var info in type.GetFields()) { var offset = (Offset64)Attribute.GetCustomAttributes(info, typeof(Offset64)).FirstOrDefault(); if (offset == null) { continue; } try { var markedDontRebase = false; var pattern = offset.Pattern; if (!pattern.Trim().EndsWith("DontRebase")) { pattern = pattern + " DontRebase"; } var results = pf.FindMany(pattern, ref markedDontRebase); if (results == null) { //Failed to find a pattern match. logr.Write("No match for {0} some functionality may not work correctly", info.Name); continue; } if (results.Length > 1) { lock (Core.Memory) { if (offset.MultipleResults) { if (results.Distinct().Count() == 1) { //Multiple matches were expected but there was only one result, double check that our pattern is still finding what we wanted logr.Write( "Multiple matches for {0} were expected, but only one result was found, some functionality may not work correctly", info.Name); } } else { //Multiple matches to the provided pattern were found and we were not expecting this logr.Write( "Multiple matches for {0} which was not expected, some functionality may not work correctly", info.Name); } } } var addrz = (long)results[0]; if (offset.Modifier != 0) { addrz = (long)(addrz + offset.Modifier); } logr.Write("[SecondaryOffsetManager] Found 0x{0:X} for {1}", addrz, info.Name); if (info.FieldType == typeof(IntPtr)) { info.SetValue(null, (IntPtr)addrz); } else { info.SetValue(null, (int)addrz); } } catch (Exception e) { //Something went wrong logr.WriteException(e); } } }); SecondaryOffsetManager.Initalized = true; }