public ORArray(XElement data) { name = (ORNames)Enum.Parse(typeof(ORNames), data.Attribute("Name").Value); size = (int)ImprovedParse.Parse(data.Attribute("Size").Value); type = (ORNames)Enum.Parse(typeof(ORNames), data.Attribute("Type").Value); string temp = data.Attribute("Address").Value; int PlusPos = -1; if ((PlusPos = temp.LastIndexOf('+')) >= 0) { address = (uint)ImprovedParse.Parse(temp.Substring(PlusPos + 1)); string ModuleName = temp.Substring(0, PlusPos); for (int i = 0; i < GameData.SC2Modules.Count; i++) { try { if (GameData.SC2Modules[i].ModuleName.Equals(ModuleName, StringComparison.OrdinalIgnoreCase)) { address += (uint)GameData.SC2Modules[i].BaseAddress; break; } } catch (System.ComponentModel.Win32Exception) { //Let's wait a tiny bit of time and try this one more time in case it was just a temporary error. System.Threading.Thread.Sleep(0); if (GameData.SC2Process.Modules[i].ModuleName.Equals(ModuleName, StringComparison.OrdinalIgnoreCase)) { address += (uint)GameData.SC2Modules[i].BaseAddress; break; } } } } else { address = (uint)ImprovedParse.Parse(data.Attribute("Address").Value); } }
public ORStruct(XElement data) { startOffset = int.MaxValue; endOffset = int.MinValue; name = (ORNames)Enum.Parse(typeof(ORNames), data.Attribute("Name").Value); size = (int)ImprovedParse.Parse(data.Attribute("Size").Value); if (data.Attribute("Address") != null) { string temp = data.Attribute("Address").Value; int PlusPos = -1; if ((PlusPos = temp.LastIndexOf('+')) >= 0) { address = (uint)ImprovedParse.Parse(temp.Substring(PlusPos + 1)); string ModuleName = temp.Substring(0, PlusPos); foreach (ProcessModule module in GameData.SC2Process.Modules) { if (module.ModuleName.Equals(ModuleName, StringComparison.OrdinalIgnoreCase)) { address += (uint)module.BaseAddress; break; } } } else { address = (uint)ImprovedParse.Parse(data.Attribute("Address").Value); } } else { address = 0; } members = new Dictionary <ORNames, ORStructMember>(); foreach (XElement member in data.Elements("Member")) { members.Add((ORNames)Enum.Parse(typeof(ORNames), member.Attribute("Name").Value), new ORStructMember(member, this)); } }
public ORStructMember(XElement data, ORStruct parent) { name = (ORNames)Enum.Parse(typeof(ORNames), data.Attribute("Name").Value); offset = 0; string Offset = data.Attribute("Offset").Value; if (!Offset.Contains('+')) { offset = (int)ImprovedParse.Parse(Offset); data.SetAttributeValue("AbsoluteOffset", null); } else { string[] Split = Offset.Split('+'); if (Split.Length == 2) { int BaseOffset = 0; if (parent.members.ContainsKey((ORNames)Enum.Parse(typeof(ORNames), Split[0]))) { BaseOffset = parent.members[(ORNames)Enum.Parse(typeof(ORNames), Split[0])].offset; } offset = BaseOffset + (int)ImprovedParse.Parse(Split[1]); data.SetAttributeValue("AbsoluteOffset", "0x" + offset.ToString("X")); } } int Size = (int)ImprovedParse.Parse(data.Attribute("Size").Value); if (offset < parent.startOffset) { parent.startOffset = offset; } if (offset + Size > parent.endOffset) { parent.endOffset = offset + Size; } string Type = data.Attribute("Type").Value; size = Size; if (data.Attribute("Count") != null) { count = (int)ImprovedParse.Parse(data.Attribute("Count").Value); } else { count = -1; } switch (Type) { case "Signed": switch (Size) { case 1: type = typeof(sbyte); break; case 2: type = typeof(Int16); break; case 4: type = typeof(Int32); break; case 8: type = typeof(Int64); break; default: type = typeof(byte); break; } break; case "Unsigned": switch (Size) { case 1: type = typeof(byte); break; case 2: type = typeof(UInt16); break; case 4: type = typeof(UInt32); break; case 8: type = typeof(UInt64); break; default: type = typeof(byte); break; } break; case "Fixed": switch (Size) { case 1: type = typeof(fixed8); break; case 2: type = typeof(fixed16); break; case 4: type = typeof(fixed32); break; default: type = typeof(byte); break; } break; case "String": type = typeof(string); break; case "Bool": type = typeof(bool); break; default: type = typeof(byte); break; } }