public static int execFindReplace(int cnt, ref Form1.CodeDB cDB, bool isCWrite) { if ((cnt + 1) >= cDB.CData.Length) { return(0); } byte[] ogp = cDB.CData[cnt + 1].codeArg1_BA; byte[] cop = cDB.CData[cnt + 1].codeArg2; ulong[] addrs = FindReplace_SearchMemory(cDB.CData[cnt].codeArg1, misc.ByteArrayToLong(cDB.CData[cnt].codeArg2, 0, 4), 1, ogp, (int)cDB.CData[cnt].codeArg0); for (int x = 0; x < addrs.Length; x++) { if (!isCWrite) { Form1.FRManager.AddItem((uint)addrs[x], ogp, cop); } Form1.apiSetMem(addrs[x], cop); } return(1); }
public static int execMultilineCondensed(int cnt, ref Form1.CodeDB cDB, bool isCWrite) { //Requires 2 lines if ((cnt + 1) >= cDB.CData.Length) { return(0); } string vincStr = cDB.CData[cnt + 1].codeArg0.ToString("X"); byte[] vinc = misc.StringBAToBA(vincStr.PadLeft((vincStr.Length % 2) + vincStr.Length, '0')); byte[] tWrite = new byte[cDB.CData[cnt].codeArg2.Length]; Array.Copy(cDB.CData[cnt].codeArg2, tWrite, tWrite.Length); ulong addr = cDB.CData[cnt].codeArg1; ulong max = misc.ByteArrayToLong(cDB.CData[cnt + 1].codeArg2, 0, cDB.CData[cnt + 1].codeArg2.Length); for (ulong x = 0; x < max; x++) { Form1.apiSetMem(addr + (x * cDB.CData[cnt + 1].codeArg1), tWrite); if (cDB.CData[cnt + 1].codeArg0 != 0) { tWrite = misc.addBA(tWrite, vinc); } } return(1); }
public static int execPointerExecute(int cnt, ref Form1.CodeDB cDB, bool isCWrite) { byte[] newAddrBA = new byte[4]; Form1.apiGetMem(cDB.CData[cnt].codeArg1, ref newAddrBA); if (Form1.doFlipArray) { Array.Reverse(newAddrBA); } ulong newAddrUL = BitConverter.ToUInt32(newAddrBA, 0); newAddrUL += misc.ByteArrayToLong(cDB.CData[cnt].codeArg2, 0, cDB.CData[cnt].codeArg2.Length); if (cDB.CData[cnt].codeArg0 == 0) { if (cnt + 1 < cDB.CData.Length) { cDB.CData[cnt + 1].codeArg1 = newAddrUL; } } else { byte[] arg2_BA = BitConverter.GetBytes((uint)newAddrUL); if (BitConverter.IsLittleEndian) { Array.Reverse(arg2_BA); } if (cnt + 1 < cDB.CData.Length) { cDB.CData[cnt + 1].codeArg2 = arg2_BA; } } return(0); }
/* * Loops through each code and calls ProcPreProcCode to run them */ public static void WriteToPS32(Form1.CodeDB Codes) { if (Codes.codes == null || Codes.CData == null) { return; } //splitList = Form1.Codes[ind].codes.Split('\n'); int skip = 0; for (int x = 0; x < Codes.CData.Length; x++) { if (Codes.CData[x].type == '\0') { break; } if (skip > 0) { skip--; goto SkipCodes; } skip = ProcPreProcCode(Codes, x); SkipCodes :; } }
/* * Processes codes in the string array splitList */ public static Form1.CodeDB ParseCodeString(string data, Form1.CodeDB db) { if (data == null) { return(db); } Form1.CodeDB ret = db; splitList = data.Split('\n'); ret.CData = new Form1.ncCode[0]; foreach (string s in splitList) { if (s != "" && s != "\r" && s.Split(' ').Length > 2) { Form1.ncCode temp = new Form1.ncCode(); Form1.ncCodeType tempCT = ncCodeTypes.Where(i => i.Command == s[0]).FirstOrDefault(); if (tempCT.Command != '\0') { temp = tempCT.ParseCode(s.Replace("\r", "")); } if (temp.codeArg2 != null) { Array.Resize(ref ret.CData, ret.CData.Length + 1); ret.CData[ret.CData.Length - 1] = temp; } } } return(ret); }
/* * Loops through each code and calls ProcPreProcCode to run them */ public static void WriteToPS32(Form1.CodeDB Codes, bool isCWrite = false) { if (Codes.codes == null || Codes.CData == null) { return; } //splitList = Form1.Codes[ind].codes.Split('\n'); int skip = 0; for (int x = 0; x < Codes.CData.Length; x++) { if (skip > 0) { skip--; goto SkipCodes; } Form1.ncCodeType tempCT = ncCodeTypes.Where(i => i.Command == Codes.CData[x].codeType).FirstOrDefault(); if (tempCT.Command != '\0') { skip = tempCT.ExecCode(x, ref Codes, isCWrite); } SkipCodes :; } }
public static int execCopyPasteBytes(int cnt, ref Form1.CodeDB cDB, bool isCWrite) { uint type = cDB.CData[cnt].codeArg0; if (type == 1) //copy { ulong cSize = misc.ByteArrayToLong(cDB.CData[cnt].codeArg2, 0, cDB.CData[cnt].codeArg2.Length); copiedBytes = new byte[cSize]; Form1.apiGetMem(cDB.CData[cnt].codeArg1, ref copiedBytes); if (!Form1.doFlipArray) { Array.Reverse(copiedBytes); } } else if (type == 2) //paste { if (copiedBytes == null) { return(0); } Form1.apiSetMem(cDB.CData[cnt].codeArg1, copiedBytes); } return(0); }
/* * Processes joker code types (both D and E type) */ public static int ParseJokerD(string[] splitList, int cnt, ref Form1.CodeDB Code, int ind2) { String code = misc.sLeft(splitList[cnt], 19); String val = misc.sRight(code, 8); if (val.IndexOf(' ') >= 0) { return(0); } Code.CData[ind2].jsize = int.Parse(misc.sLeft(val, 2), NumberStyles.HexNumber); Array.Resize(ref Code.CData, Code.CData.Length + Code.CData[ind2].jsize); int x = 0, y = 0, ret = Code.CData[ind2].jsize; Code.CData[ind2].jbool = BitConverter.GetBytes(int.Parse(misc.ReverseE("00" + misc.sRight(val, 6), 8), NumberStyles.HexNumber)); ind2++; for (x = 0; x < ret; x++) { do { y++; if ((cnt + y) >= splitList.Length) { return(ind2); } code = misc.sLeft(splitList[cnt + y], 19); } while (code == null || code == "" || CheckForComment(code) == 1); int len = 0; Code.CData[ind2].type = code[0]; switch (Code.CData[ind2].type) { case '0': len = 2; break; case '1': len = 4; break; case '2': case '6': case 'D': case 'E': len = 8; break; } Code.CData[ind2].addr = ulong.Parse(misc.sMid(code, 2, 8), NumberStyles.HexNumber); Code.CData[ind2].val = BitConverter.GetBytes(int.Parse(misc.ReverseE(misc.sRight(code, len), 8), NumberStyles.HexNumber)); ind2++; } return(ind2); }
public static int execCopyBytes(int cnt, ref Form1.CodeDB cDB, bool isCWrite) { byte[] copied = new byte[cDB.CData[cnt].codeArg0]; Form1.apiGetMem(cDB.CData[cnt].codeArg1, ref copied); if (!Form1.doFlipArray) { Array.Reverse(copied); } Form1.apiSetMem(misc.ByteArrayToLong(cDB.CData[cnt].codeArg2, 0, 4), copied); return(0); }
/* * Saves the code database save into file */ public static void SaveFile(string file, Form1.CodeDB save) { if (file == "" || file == null) { System.Windows.Forms.MessageBox.Show("Error: File path invalid!"); return; } string[] str = { "{", save.state.ToString(), save.name, save.codes, "}\n" }; System.IO.File.WriteAllLines(file, str); }
public static int execByteWrite(int cnt, ref Form1.CodeDB cDB, bool isCWrite) { byte[] t; int x = 0; switch (cDB.CData[cnt].codeArg0) { case 1: //OR t = new byte[cDB.CData[cnt].codeArg2.Length]; Form1.apiGetMem(cDB.CData[cnt].codeArg1, ref t); for (x = 0; x < t.Length; x++) { t[x] |= cDB.CData[cnt].codeArg2[x]; } Form1.apiSetMem(cDB.CData[cnt].codeArg1, t); break; case 2: //AND t = new byte[cDB.CData[cnt].codeArg2.Length]; Form1.apiGetMem(cDB.CData[cnt].codeArg1, ref t); for (x = 0; x < t.Length; x++) { t[x] &= cDB.CData[cnt].codeArg2[x]; } Form1.apiSetMem(cDB.CData[cnt].codeArg1, t); break; case 3: //XOR t = new byte[cDB.CData[cnt].codeArg2.Length]; Form1.apiGetMem(cDB.CData[cnt].codeArg1, ref t); for (x = 0; x < t.Length; x++) { t[x] ^= cDB.CData[cnt].codeArg2[x]; } Form1.apiSetMem(cDB.CData[cnt].codeArg1, t); break; default: Form1.apiSetMem(cDB.CData[cnt].codeArg1, cDB.CData[cnt].codeArg2); break; } return(0); }
public static int execMUConditionalExecute(int cnt, ref Form1.CodeDB cDB, bool isCWrite) { bool execute = false; byte[] cmp = new byte[cDB.CData[cnt].codeArg2.Length]; Form1.apiGetMem(cDB.CData[cnt].codeArg1, ref cmp); execute = misc.ArrayCompare(cDB.CData[cnt].codeArg2, cmp, null, Form1.compANEq); if (!execute) { return((int)cDB.CData[cnt].codeArg0); } else { return(0); } }
/* * Opens a code database */ public static Form1.CodeDB[] OpenFile(string file) { Form1.CodeDB[] ret = null; int z = 1; if (file == "" || file == null) { System.Windows.Forms.MessageBox.Show("Error: File path invalid!"); return(ret); } string[] tempStr; tempStr = File.ReadAllLines(file); int len = 0, y = 0; while (y < tempStr.Length) { if (tempStr[y] == "}") { len++; } y++; } ret = new Form1.CodeDB[len]; for (int x = 0; z < tempStr.Length; x++) { ret[x].state = bool.Parse(tempStr[z]); z++; ret[x].name = tempStr[z]; z++; while (tempStr[z] != "}") { ret[x].codes += tempStr[z] + '\n'; z++; } z += 2; } return(ret); }
public static Form1.ncCode[] ParseCodeStringFull(string data) { //Remove comments var re = @"(@(?:""[^""]*"")+|""(?:[^""\n\\]+|\\.)*""|'(?:[^'\n\\]+|\\.)*')|//.*|/\*(?s:.*?)\*/"; data = System.Text.RegularExpressions.Regex.Replace(data, re, "$1"); if (data == "" || data == null) { return(new Form1.ncCode[1]); } Form1.CodeDB db = new Form1.CodeDB(); db = ParseCodeString(data, db); if (db.CData == null || db.CData.Length == 0) { return(new Form1.ncCode[1]); } return(db.CData); }
/* * Loops through each code (if it is a write) it grabs what the data is */ public static Form1.ncCode[] CreateBackupPS3(Form1.CodeDB Codes) { if (Codes.CData == null) { return(new Form1.ncCode[0]); } Form1.ncCode[] ret = new Form1.ncCode[0]; int isPointerWrite = 0; ulong arg1 = 0; foreach (Form1.ncCode nC in Codes.CData) { if (nC.codeType == '0' || nC.codeType == '1' || nC.codeType == '2') { Array.Resize(ref ret, ret.Length + 1); int ind = ret.Length - 1; ret[ind] = new Form1.ncCode(); ret[ind].codeType = nC.codeType; ret[ind].codeArg0 = nC.codeArg0; if (isPointerWrite == 1) { ret[ind].codeArg1 = arg1; isPointerWrite = 0; } else if (isPointerWrite == 2) { byte[] arg1_BA = BitConverter.GetBytes((uint)arg1); if (BitConverter.IsLittleEndian) { Array.Reverse(arg1_BA); } ret[ind].codeArg2 = arg1_BA; isPointerWrite = 0; } else { ret[ind].codeArg1 = nC.codeArg1; } ret[ind].codeArg2 = new byte[nC.codeArg2.Length]; Form1.apiGetMem(ret[ind].codeArg1, ref ret[ind].codeArg2); } else if (nC.codeType == '6') { byte[] arg1_BA = BitConverter.GetBytes((uint)arg1); if (BitConverter.IsLittleEndian) { Array.Reverse(arg1_BA); } byte[] addr = new byte[4]; ulong arg1Addr = (isPointerWrite == 1) ? arg1 : nC.codeArg1; byte[] arg2Off = (isPointerWrite == 2) ? arg1_BA : nC.codeArg2; Form1.apiGetMem(arg1Addr, ref addr); if (!Form1.doFlipArray) { Array.Reverse(addr); } ulong newAddrUL = BitConverter.ToUInt32(addr, 0); newAddrUL += misc.ByteArrayToLong(arg2Off, 0, arg2Off.Length); arg1 = newAddrUL; isPointerWrite = ((nC.codeArg0 == 1) ? 2 : 1); } } return(ret); }
/* * Opens a code database */ public static Form1.CodeDB[] OpenFile(string file) { Form1.CodeDB[] ret = null; if (file == "" || file == null) { System.Windows.Forms.MessageBox.Show("Error: File path invalid!"); return(ret); } string[] tempStr; tempStr = File.ReadAllLines(file); int len = 0, y = 0; while (y < tempStr.Length) { if (tempStr[y] == "#") { len++; } y++; } ret = new Form1.CodeDB[len]; int z = 1; //start on second line of file for (int x = 0; z < tempStr.Length; x++) { if (tempStr[z] == "") { z += 3; } switch (tempStr[z]) { case "0": tempStr[z] = tempStr[z].Replace("0", "False"); ret[x].state = bool.Parse(tempStr[z]); z--; ret[x].name = tempStr[z]; break; case "1": tempStr[z] = tempStr[z].Replace("1", "True"); ret[x].state = bool.Parse(tempStr[z]); z--; ret[x].name = tempStr[z]; break; default: ret[x].state = false; z--; ret[x].name = tempStr[z]; z--; break; } //if (tempStr[z] == "") //{ // x++; //} //if (tempStr[z] == "0") //{ //} if (file.Substring((file.Length - 4), 4) == ".ncl") { z += 3; //To skip the code creator name } else { z += 2; } while (tempStr[z] != "#") { ret[x].codes += tempStr[z] + '\n'; z++; } z += 2; } return(ret); }
/* * Opens a code database */ public static Form1.CodeDB[] OpenFile(string file) { if (!File.Exists(file)) { return(null); } Form1.CodeDB[] ret = null; int z = 1; if (file == "" || file == null) { System.Windows.Forms.MessageBox.Show("Error: File path invalid!"); return(ret); } string codeFile = File.ReadAllText(file); string[] tempStr = codeFile.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); int len = 0, y = 0, x = 0; bool isGPS3F = false; while (y < tempStr.Length) { if (tempStr[y] == "}") { len++; isGPS3F = false; } else if (tempStr[y] == "#") { len++; isGPS3F = true; } y++; } ret = new Form1.CodeDB[len]; if (isGPS3F) { string[] gfArr = codeFile.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); for (x = 0; x < len; x++) { string[] lines = gfArr[x].Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); ret[x].name = lines[0]; ret[x].state = lines[1] == "1"; ret[x].codes = String.Join(Environment.NewLine, lines, 2, lines.Length - 2); } } else { for (x = 0; z < tempStr.Length; x++) { if (x >= ret.Length) { break; } ret[x].state = bool.Parse(tempStr[z]); z++; ret[x].name = tempStr[z]; z++; ret[x].codes = ""; while (tempStr[z] != "}") { ret[x].codes += tempStr[z] + "\r\n"; z++; } if (ret[x].codes != "") { ret[x].codes = ret[x].codes.Remove(ret[x].codes.Length - 1); } z += 2; } } return(ret); }
/* * Processes codes in the string array splitList */ public static void ParseCodeString(string data, ref Form1.CodeDB ret) { int strcnt = 0, skip = 0, cnt = 0; splitList = data.Split('\n'); ret.CData = new Form1.CodeData[0]; foreach (string s in splitList) { int check = CheckForComment(splitList[strcnt]); if (check == 1 || Form1.bComment == true || splitList[strcnt] == "") { goto SkipUpdateCD; } if (skip > 0) { skip--; goto SkipUpdateCD; } String code = misc.sLeft(splitList[strcnt], 19); String val = misc.sRight(code, 8); if (val.Length != 8 || code.Length != 19) { goto SkipUpdateCD; } Array.Resize(ref ret.CData, ret.CData.Length + 1); if (cnt != 0 && ret.CData[cnt - 1].type != '6') { ret.CData[cnt].addr = ulong.Parse(misc.sMid(code, 2, 8), NumberStyles.HexNumber); } else if (cnt == 0) { ret.CData[cnt].addr = ulong.Parse(misc.sMid(code, 2, 8), NumberStyles.HexNumber); } ret.CData[cnt].type = splitList[strcnt][0]; switch (ret.CData[cnt].type) { case '0': //8 bit write if (val.IndexOf(' ') >= 0) { break; } ret.CData[cnt].val = new byte[] { byte.Parse(misc.sLeft(val, 2), NumberStyles.HexNumber) }; break; case '1': //16 bit write if (val.IndexOf(' ') >= 0) { break; } byte[] sVal = BitConverter.GetBytes(int.Parse(misc.ReverseE(misc.sLeft(val, 4), 4), NumberStyles.HexNumber)); ret.CData[cnt].val = new byte[2] { sVal[0], sVal[1] }; break; case '2': //32 bit write if (val.IndexOf(' ') >= 0) { break; } ret.CData[cnt].val = BitConverter.GetBytes(int.Parse(misc.ReverseE(misc.sLeft(val, 8), 8), NumberStyles.HexNumber)); break; case '6': //Pointer write ret.CData[cnt].val = BitConverter.GetBytes(int.Parse(misc.ReverseE(misc.sLeft(val, 8), 8), NumberStyles.HexNumber)); int y = 1; if (splitList.Length <= (cnt + y)) { break; } //Skip comments and whatnot check = CheckForComment(splitList[cnt + y]); if (check == 1 || Form1.bComment == true) { y++; } else if (check == 2) { while (Form1.bComment == true) { y++; if (splitList.Length <= (cnt + y)) { break; } CheckForComment(splitList[cnt + y]); } } byte[] pretByte = new byte[0x4]; Form1.apiGetMem(ret.CData[cnt].addr, ref pretByte); if (splitList.Length <= (cnt + y)) { break; } Array.Resize(ref ret.CData, ret.CData.Length + 1); ret.CData[cnt + 1].addr = (misc.ByteArrayToLong(pretByte, 0, 4) + ulong.Parse(misc.sLeft(val, 8), NumberStyles.HexNumber)); ret.CData[cnt + 1].val = BitConverter.GetBytes(int.Parse(misc.sRight(splitList[cnt + y], 8), System.Globalization.NumberStyles.HexNumber)); ret.CData[cnt + 1].type = splitList[cnt + y][0]; break; case 'D': case 'E': //Joker skip = ParseJokerD(splitList, strcnt, ref ret, cnt); skip -= (cnt + 1); cnt = skip + cnt; break; } cnt++; SkipUpdateCD: strcnt++; } }
/* * Runs codes that have already been processed */ public static int ProcPreProcCode(Form1.CodeDB Codes, int cnt) { ulong addr = Codes.CData[cnt].addr; byte[] val = Codes.CData[cnt].val; byte[] jval = Codes.CData[cnt].jbool; char type = Codes.CData[cnt].type; int skip = 0; //Make upper case if (type >= 0x61) { type -= (char)0x20; } switch (type) { case '0': byte[] stw0 = new byte[1]; stw0[0] = val[val.Length - 1]; Form1.apiSetMem(addr, stw0); break; case '1': byte[] stw1 = new byte[2]; stw1[0] = val[val.Length - 2]; stw1[1] = val[val.Length - 1]; Form1.apiSetMem(addr, val); break; case '2': Form1.apiSetMem(addr, val); //PS3TMAPI.ProcessSetMemory(0, PS3TMAPI.UnitType.PPU, Form1.ProcessID, 0, addr, val); break; case '6': byte[] pretByte = new byte[4]; Form1.apiGetMem(addr, ref pretByte); //apiGetMem(addr, ref pretByte); Codes.CData[cnt + 1].addr = (misc.ByteArrayToLong(pretByte, 0, 4) + misc.ByteArrayToLong(val, 0, 4)); //ProcPreProcCode(Codes, cnt + 1); break; case 'D': case 'E': int size = Codes.CData[cnt].jsize; skip = size; byte[] retByte = new byte[0x4]; Form1.apiGetMem(addr, ref retByte); //apiGetMem(addr, ref retByte); bool ret = false; if (type == 'D') { ret = misc.ArrayCompare(jval, retByte, new byte[1], 4, 0, 0, Form1.compEq); } else if (type == 'E') { ret = misc.ArrayCompare(jval, retByte, new byte[1], 4, 0, 0, Form1.compANEq); } if (ret == false) { break; } for (int x = (cnt + 1); x < (size + cnt + 1); x++) { ProcPreProcCode(Codes, x); } break; } return(skip); }