Reputation: 219
I'm trying to write some byte to a game.
Function source code:
public void updateStatistic(string prestigeValue, string experience, string winrate, string loserate)
{
VAMemory vam = new VAMemory(process);
vam.WriteByte((IntPtr)0x145D114B9, byte.Parse(prestigeValue));
vam.WriteByte((IntPtr)0x145D114B5, byte.Parse(experience));
vam.WriteByte((IntPtr)0x145D10E05, byte.Parse(winrate));
vam.WriteByte((IntPtr)0x145D12240, byte.Parse(loserate));
}
Sadly I'm receiving the following error message:
An unhandled exception of type 'System.OverflowException' occurred in mscorlib.dll
Additional information: The value for an unsigned byte was too large or too small.
The type of the address is 4 Bytes. And the values I'm trying to post are: prestigeValue = 1, experience = 1500000, winrate = 100, loserate= 50
Does anyone have a idea how I could get this working?
Upvotes: 1
Views: 3767
Reputation: 817
Ok, first lets start from the beginning.
The VAMemory is a DLL obtained from probably this reference. http://www.vivid-abstractions.net/logical/programming/vamemory-c-memory-class-net-3-5/
It allows you to write to a particular memory location. Very useful for doing certain things.
Since the value you are trying to write is a 32bit value. Why don't you use
vam.WriteInt32((IntPtr)0x145D114B5, byte.Parse(experience));
instead?
Or alternatively, you could probably break your bytes up into single bytes like
var experience_int = int.parse(experience);
vam.WriteByte((IntPtr)0x145D114B5, (byte)experience_int & 0xFF);
vam.WriteByte((IntPtr)0x145D114B6, (byte)(experience_int>>8) & 0xFF);
vam.WriteByte((IntPtr)0x145D114B7, (byte)(experience_int>>16 & 0xFF);
vam.WriteByte((IntPtr)0x145D114B8, (byte)(experience_int>>24) & 0xFF);
Note that I did not test the code, nor did I check the ordering but it should be something like this.
For more information: The reason why you get the exception mentioned is because when you call Byte.Parse() but the string that you put in is greater than 255. As you can see mscorlib.dll is the place that is throwing the exception. Inside the MSCoreLib, the exception is throw like this.
if (num < 0 || num > (int) byte.MaxValue)
throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
Upvotes: 2
Reputation: 275
Try to use int.Parse(value)
1500000 is too big of a number to store in a byte.
EDIT: You also need to find a method that writes an int to memory.
Upvotes: 0