public bool WriteData(int index, bool reset) { ulong address = this.getAddress(); BatchCode code = Codes[index]; if (reset && string.IsNullOrEmpty(code.reset)) { return(true); } byte[] data = this.GetData(index, reset); int offset = code.offset; address = address + (ulong)offset; if (CheatList.IS_DEV) { } else { MemoryHelper.WriteMemory(address, data); } return(true); }
public override bool Parse(string[] cheat_elements, ref int start_idx, bool simple_format) { string str = cheat_elements[start_idx]; this.cheat_code = str; string[] datas = str.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < datas.Length; i++) { string cstr = datas[i]; if (string.IsNullOrEmpty(cstr)) { continue; } BatchCode code = this.ParseCode(cstr); this.Codes.Add(code); } ++start_idx; if (CheatList.IS_DEV) { this.GetData(0, false); } return(true); }
private BatchCode ParseCode(string data) { string[] elements = data.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); BatchCode code = new BatchCode(); BatchType batchType = BatchType.VALUE; int target = 0; int step = 0; int offset = 0; int skip = 0; int size = -1; string cheatVal = null; string resetVal = null; ValueType vtype = ValueType.NONE_TYPE; foreach (string elm in elements) { string[] buff = elm.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries); string key = buff[0]; string value = buff[1]; switch (key) { case "for": batchType = BatchType.FOR; target = (int)NumberBytesHelper.ParseString(value); break; case "if": batchType = BatchType.IF; target = int.Parse(value); break; case "step": if (value.StartsWith("0x")) { step = int.Parse(value.Substring(2), NumberStyles.HexNumber); break; } step = int.Parse(value); break; case "offset": offset = decimal.ToInt32(NumberBytesHelper.ParseString(value)); break; case "skip": skip = (int)NumberBytesHelper.ParseString(value); break; case "value": cheatVal = value; break; case "reset": resetVal = value; break; break; case "size": size = (int)NumberBytesHelper.ParseString(value); break; case "vtype": switch (value) { case "float": vtype = ValueType.FLOAT_TYPE; break; case "double": vtype = ValueType.DOUBLE_TYPE; break; } break; case "excludes": NumberExcluder excluder = new NumberExcluder(); excluder.Parse(value); code.excluder = excluder; break; } } if (size < 1 && cheatVal.StartsWith("0x")) { string tmp = cheatVal.Substring(2); size = (tmp.Length + 1) / 2; size = size > 2 ? (size + 3) / 4 * 4 : size; } size = size < 1 ? 4 : size; if (cheatVal.StartsWith("0x")) { cheatVal = "0x" + cheatVal.Substring(2).PadLeft(size * 2, '0'); } code.value = cheatVal; if (!string.IsNullOrEmpty(resetVal) && resetVal.StartsWith("0x")) { resetVal = "0x" + resetVal.Substring(2).PadLeft(size * 2, '0'); } code.reset = resetVal; if (ValueType.NONE_TYPE.Equals(vtype)) { switch (size) { case 1: vtype = ValueType.BYTE_TYPE; break; case 2: vtype = ValueType.USHORT_TYPE; break; case 4: vtype = ValueType.UINT_TYPE; break; case 8: vtype = ValueType.ULONG_TYPE; break; default: vtype = ValueType.HEX_TYPE; break; } } code.batchType = batchType; code.target = target; code.step = step; code.skip = skip; code.size = size; code.offset = offset; code.vtype = vtype; return(code); }
private byte[] GetData(int index, bool reset) { ulong address = this.getAddress(); BatchCode code = Codes[index]; byte[] data = null; string value = code.value; if (reset) { value = code.reset; } ValueType vtype = code.vtype; int size = code.size; int psize = size + code.skip; decimal baseVal = 0; byte[] stepData = null; if (code.step != 0) { string hexStr = String.Format("{0:X}", code.step); stepData = NumberBytesHelper.HexToBytes(hexStr); } if (value.StartsWith("0x")) { string str = value.Substring(2); data = MemoryHelper.string_to_hex_bytes(str); if (size < 9) { string[] strs = new string[str.Length / 2]; for (int i = 0; i < strs.Length; i++) { strs[i] = str.Substring(i * 2, 2); } Array.Reverse(strs); str = String.Join("", strs); baseVal = ulong.Parse(str, NumberStyles.HexNumber); } } else { baseVal = Convert.ToDecimal(value); data = this.convertValue(baseVal, vtype); } if (BatchType.VALUE.Equals(code.batchType)) { return(data); } int dataSize = code.GetDataSize(); int offset = code.offset; address = address + (ulong)offset; byte[] buff = null; if (CheatList.IS_DEV) { buff = new byte[dataSize]; } else { buff = MemoryHelper.ReadMemory(address, dataSize); } decimal val = baseVal; int pos = 0; NumberExcluder excluder = code.excluder; bool ignore = false; int begin = code.begin + 1; int end = code.target + 1; switch (code.batchType) { case BatchType.FOR: for (int i = begin; i < end; i++) { if (excluder != null) { ignore = excluder.Match(i); } if (!ignore) { if (size < 9 && val != baseVal) { data = this.convertValue(val, vtype); } Buffer.BlockCopy(data, 0, buff, pos, code.size); pos += psize; } if (!reset) { if (size < 9) { val += code.step; } else if (stepData != null) { data = NumberBytesHelper.Add(data, stepData); } } } break; } return(buff); }