public void write_function_throws_invcastexception() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightPlayerAddress, TLMemoryInfo.torchlightPlayerGoldOffsets); Exception ex = Assert.Throws <InvalidCastException>(() => torchlightProcess.write <decimal>(mainPTR, playerGoldToSet)); Assert.Equal(TLMemoryInfo.exceptionMessage, ex.Message); }
public void read_function_reads_rawbytes() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightUIAddress, TLMemoryInfo.torchlightUIACLabelOffsets); byte[] dataBuffer = torchlightProcess.read <byte[]>(mainPTR, rawBytes.Length); for (int i = 0; i < rawBytes.Length; i++) { Assert.Equal(dataBuffer[i], rawBytes[i]); } }
public void read_functions_reads_AOBHexString() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightUIAddress, TLMemoryInfo.torchlightUIACLabelOffsets); string[] dataBuffer = torchlightProcess.read <string[]>(mainPTR, AOB.Length); for (int i = 0; i < AOB.Length; i++) { Assert.Equal(dataBuffer[i], AOB[i]); } }
public void write_function_writes_string() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightUIAddress, TLMemoryInfo.torchlightUIACLabelOffsets); bool iswritten = torchlightProcess.write <string>(mainPTR, UIACLabel); Assert.Equal(iswritten, true); string memoryStringValue = torchlightProcess.read <string>(mainPTR, UIACLabel.Length); Assert.Equal(memoryStringValue, UIACLabel); }
public void write_function_writes_int() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightPlayerAddress, TLMemoryInfo.torchlightPlayerGoldOffsets); bool iswritten = torchlightProcess.write <int>(mainPTR, playerGoldToSet); Assert.Equal(iswritten, true); double memoryGoldValue = torchlightProcess.read <int>(mainPTR); Assert.Equal(memoryGoldValue, playerGoldToSet); }
public void write_function_writes_byte() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightPlayerAddress, TLMemoryInfo.torchlightPlayerSkillOffsets); bool iswritten = torchlightProcess.write <byte>(mainPTR, playerSkillPointsToSet); Assert.Equal(iswritten, true); byte memorySKPValue = torchlightProcess.read <byte>(mainPTR); Assert.Equal(memorySKPValue, playerSkillPointsToSet); }
public void write_function_writes_float() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightPlayerAddress, TLMemoryInfo.torchlightPlayerManaOffsets); bool iswritten = torchlightProcess.write <float>(mainPTR, playerManaToSet); Assert.Equal(iswritten, true); float memoryManaValue = torchlightProcess.read <float>(mainPTR); Assert.Equal(memoryManaValue, playerManaToSet); }
public void write_function_writes_rawAOB() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightUIAddress, TLMemoryInfo.torchlightUIACLabelOffsets); bool iswritten = torchlightProcess.write <byte[]>(mainPTR, rawBytes); Assert.Equal(iswritten, true); byte[] memoryBytes = torchlightProcess.read <byte[]>(mainPTR, rawBytes.Length); for (int i = 0; i < rawBytes.Length; i++) { Assert.Equal(memoryBytes[i], rawBytes[i]); } }
/// <summary> /// Writes the given value to the address that was calculated. /// </summary> /// <typeparam name="T">Data type to write</typeparam> /// <param name="ptrObj">Calculated ptrObject <see cref="create_ptr_object(int, int[])"/> function.</param> /// <param name="value">Data to write.</param> /// <returns>True on success.</returns> public bool write <T>(ptrObject ptrObj, object value) { int sizeoft; if (typeof(T) == typeof(string)) { sizeoft = value.ToString().Length; } else if (typeof(T) == typeof(byte[])) { sizeoft = ((byte[])value).Length; } else if (typeof(T) == typeof(string[])) { sizeoft = ((string[])value).Length; } else { sizeoft = Marshal.SizeOf(typeof(T)); } return(WriteProcessMemory(ptrObj.processHandle, ptrObj.calculatedAddress, prepWriteData <T>(value), sizeoft, ref g_bytesRead)); }
public void read_function_reads_string() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightUIAddress, TLMemoryInfo.torchlightUIACLabelOffsets); Assert.Equal(UIACLabel, torchlightProcess.read <string>(mainPTR, UIACLabel.Length)); }
public void read_function_reads_long() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightPlayerAddress, TLMemoryInfo.torchlightPlayerGoldOffsets); Assert.Equal(playerGoldLong, torchlightProcess.read <long>(mainPTR)); }
public void read_function_reads_double() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightPlayerAddress, TLMemoryInfo.torchlightPlayerStatsOffsets); Assert.Equal(playerStats, torchlightProcess.read <double>(mainPTR)); }
public void read_function_reads_byte() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightPlayerAddress, TLMemoryInfo.torchlightPlayerSkillOffsets); Assert.Equal(playerSkillPoints, torchlightProcess.read <byte>(mainPTR)); }
public void read_function_reads_float() { mainPTR = torchlightProcess.create_ptr_object(TLMemoryInfo.torchlightPlayerAddress, TLMemoryInfo.torchlightPlayerManaOffsets); Assert.Equal(playerFullMana, torchlightProcess.read <float>(mainPTR)); }
/// <summary> /// Read the address and converts it to the given data type. /// </summary> /// <typeparam name="T">Returning Type</typeparam> /// <param name="ptrObj">Calculated ptrObject</param> /// <param name="readLength">For string and array types</param> /// <returns>Value that the given address holds.</returns> public T read <T>(ptrObject ptrObj, int readLength = -1) { int sizeoft; if (readLength != -1) // For strings and array types. { sizeoft = readLength; } else { sizeoft = Marshal.SizeOf(typeof(T)); } byte[] dataBuffer = new byte[sizeoft]; ReadProcessMemory(ptrObj.processHandle, ptrObj.calculatedAddress, dataBuffer, sizeoft, ref g_bytesRead); // Check here for more info about this if statement https://msdn.microsoft.com/en-us/library/system.bitconverter.islittleendian(v=vs.110).aspx if (!BitConverter.IsLittleEndian) { Array.Reverse(dataBuffer); } // Rest just returning converted data. if (typeof(T) == typeof(int)) { return((T)(object)BitConverter.ToInt32(dataBuffer, 0)); } else if (typeof(T) == typeof(float)) { return((T)(object)BitConverter.ToSingle(dataBuffer, 0)); } else if (typeof(T) == typeof(double)) { return((T)(object)BitConverter.ToDouble(dataBuffer, 0)); } else if (typeof(T) == typeof(short)) { return((T)(object)BitConverter.ToInt16(dataBuffer, 0)); } else if (typeof(T) == typeof(long)) { return((T)(object)BitConverter.ToInt64(dataBuffer, 0)); } else if (typeof(T) == typeof(byte)) { return((T)(object)dataBuffer[0]); } else if (typeof(T) == typeof(string)) { return((T)(object)Encoding.UTF8.GetString(dataBuffer)); } else if (typeof(T) == typeof(byte[])) { return((T)(object)dataBuffer); } /* string[] is completely arbitrary. Its literally just the same as byte[] * but instead of numeric bytes you see hexadecimal values as strings. */ else if (typeof(T) == typeof(string[])) { return((T)(object)(BitConverter.ToString(dataBuffer).Split('-'))); } throw new InvalidCastException("The data type you have entered is not valid."); }