private void CheckLenArg(uint len, Core.DataType type) { if ((type == Core.DataType.None || type == Core.DataType.String) && len <= 0) { throw new Exception("Length must be greater than 0 when type is None or String."); } }
public DataBlock(byte[] d, Path p, uint o, Core.DataType t = Core.DataType.None) { data = d; dataLen = (uint)d.Length; pathId = p; offset = o; dataType = t; }
//public DataBlock() { } public DataBlock(Racer racer, Path path, uint off, Core.DataType type, uint len = 4) { pathId = path; offset = off; dataType = type; dataLen = Core.DataTypeLength(type) > 0 ? Core.DataTypeLength(type) : len; Update(racer); }
public dynamic GetValue(Racer racer, DataBlock.Path path, uint offset, Core.DataType type, uint length) { int index = ValueExists(path, offset, length); if (index < 0) { data.Add(new DataBlock(racer, path, offset, type, length)); return(data.Last().GetValue(offset, type, length)); } else { return(data[index].GetValue(offset, type, length)); } }
public dynamic GetValue(uint off, Core.DataType type = Core.DataType.Single, uint len = 0) { CheckDataLoaded(); CheckLenArg(len, type); CheckContainsValue(off, len); uint sanitizedLen = Core.DataTypeLength(type) > 0 ? Core.DataTypeLength(type) : len; byte[] sanitizedData = new byte[sanitizedLen]; Array.Copy(data, off - offset, sanitizedData, 0, sanitizedLen); switch (type) { case Core.DataType.String: return(Encoding.Default.GetString(sanitizedData)); case Core.DataType.Byte: return(sanitizedData[0]); case Core.DataType.SByte: return((sbyte)sanitizedData[0]); case Core.DataType.Int16: return(BitConverter.ToInt16(sanitizedData, 0)); case Core.DataType.UInt16: return(BitConverter.ToUInt16(sanitizedData, 0)); case Core.DataType.Int32: return(BitConverter.ToInt32(sanitizedData, 0)); case Core.DataType.UInt32: return(BitConverter.ToUInt32(sanitizedData, 0)); case Core.DataType.Single: return(BitConverter.ToSingle(sanitizedData, 0)); case Core.DataType.Int64: return(BitConverter.ToInt64(sanitizedData, 0)); case Core.DataType.UInt64: return(BitConverter.ToUInt64(sanitizedData, 0)); case Core.DataType.Double: return(BitConverter.ToDouble(sanitizedData, 0)); default: return(sanitizedData); } }
// GENERIC FUNCTIONS private dynamic GetData(uint[] path, Core.DataType type, uint len = 4) { IntPtr addr; if (CheckGame()) { try { addr = GetMemoryAddr(game, path); } catch (Exception) { return(false); } uint defLen = 4; switch (type) { case Core.DataType.Byte: return(mem.ReadMemory(addr, 1, out bytesOut)[0]); case Core.DataType.UInt16: return(BitConverter.ToUInt16(mem.ReadMemory(addr, 2, out bytesOut), 0)); case Core.DataType.UInt32: return(BitConverter.ToUInt32(mem.ReadMemory(addr, 4, out bytesOut), 0)); case Core.DataType.UInt64: return(BitConverter.ToUInt64(mem.ReadMemory(addr, 8, out bytesOut), 0)); case Core.DataType.Single: return(BitConverter.ToSingle(mem.ReadMemory(addr, 4, out bytesOut), 0)); case Core.DataType.Double: return(BitConverter.ToDouble(mem.ReadMemory(addr, 8, out bytesOut), 0)); case Core.DataType.String: return(BitConverter.ToString(mem.ReadMemory(addr, len > 0 ? len : defLen, out bytesOut), 0)); default: return(mem.ReadMemory(addr, len > 0 ? len : defLen, out bytesOut)); } } else { throw new Exception("Game process not assigned."); } }
public IPropertyCustomizer Type(Core.DataType dataType) { propertyCustomizerHolder.DataType = dataType; return(this); }
// STATIC public dynamic GetData(Addr.Static datapoint, uint len = 0) { uint[] path = { (uint)datapoint }; Core.DataType type = len > 0 ? Core.DataType.None : Addr.GetType(datapoint); return(GetData(path, type, Math.Max(0, len))); }
// POD STATE public dynamic GetData(Addr.PodState datapoint, uint len = 0) { uint[] path = { (uint)Addr.BasePtr.Pod, (uint)Addr.Pod.PtrPodState, (uint)datapoint }; Core.DataType type = len > 0 ? Core.DataType.None : Addr.GetType(datapoint); return(GetData(path, type, Math.Max(0, len))); }