C# - Why it is not working

Posts 1–15 of 17 · Page 1 of 2
C# - Why it is not working
I'm trying to make a Squad Points Editor but not happens when I click the button, here is the code (please help me to fix it):

Form1 (Main Class):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace COD_Squad_Points_Editor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

CC.ProcessName = "iw6mp64_ship";
label2.Text = CC.Read._String(0x44C2E40, 4);
}

private void btnapply_Click(object sender, EventArgs e)
{
CC.Write._String(0x44C2E40, squadpoints.Text);
}
}
}
CC (MemoryHack Class):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace COD_Squad_Points_Editor
{
internal class CC
{
private static string ProcName = "";
private static IntPtr pHandle = IntPtr.Zero;
[System.Runtime.InteropServices.DllImport("kernel32 .dll", SetLastError = true)]
static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);
[System.Runtime.InteropServices.DllImport("kernel32 .dll", SetLastError = true)]
static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [System.Runtime.InteropServices.Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);

public static string ProcessName
{ get { return ProcName; } set { if (System.Diagnostics.Process.GetProcessesByName(val ue).Length != 0) { pHandle = System.Diagnostics.Process.GetProcessesByName(valu e)[0].Handle; ProcName = value; } else { System.Windows.Forms.MessageBox.Show(value + "\n\n Not Found!", "Error:" + value, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); ProcName = ""; } } }

public class Write
{
public static void _Int16(Int64 Address, Int16 Value)
{
if (System.Diagnostics.Process.GetProcessesByName(Pro cName).Length != 0)
{
IntPtr retByt;
WriteProcessMemory(pHandle, new IntPtr(Address), BitConverter.GetBytes(Value), sizeof(Int16), out retByt);
}
}
public static void _Int32(Int64 Address, Int32 Value)
{
if (System.Diagnostics.Process.GetProcessesByName(Pro cName).Length != 0)
{
IntPtr retByt;
WriteProcessMemory(pHandle, new IntPtr(Address), BitConverter.GetBytes(Value), sizeof(Int32), out retByt);
}
}
public static void _Int64(Int64 Address, Int64 Value)
{
if (System.Diagnostics.Process.GetProcessesByName(Pro cName).Length != 0)
{
IntPtr retByt;
WriteProcessMemory(pHandle, new IntPtr(Address), BitConverter.GetBytes(Value), sizeof(Int64), out retByt);
}
}
public static void _Float(Int64 Address, Single Float)
{
if (System.Diagnostics.Process.GetProcessesByName(Pro cName).Length != 0)
{
IntPtr retByt;
WriteProcessMemory(pHandle, new IntPtr(Address), BitConverter.GetBytes(Float), sizeof(Single), out retByt);
}
}
public static void _String(Int64 Address, String Value)
{
if (System.Diagnostics.Process.GetProcessesByName(Pro cName).Length != 0)
{
IntPtr retByt;
WriteProcessMemory(pHandle, new IntPtr(Address), ASCIIEncoding.ASCII.GetBytes(Value), sizeof(Int64), out retByt);
}
}
public static void _Bytes(Int64 Address, Byte[] Value)
{
if (System.Diagnostics.Process.GetProcessesByName(Pro cName).Length != 0)
{
IntPtr retByt;
WriteProcessMemory(pHandle, new IntPtr(Address), Value, Value.Length, out retByt);
}
}
}
public class Read
{
public static Int16 _Int16(Int64 Address)
{
if (System.Diagnostics.Process.GetProcessesByName(Pro cName).Length != 0)
{
IntPtr retByt; Byte[] buffer = new Byte[sizeof(Int16)];
ReadProcessMemory(pHandle, new IntPtr(Address), buffer, sizeof(Int16), out retByt);
return BitConverter.ToInt16(buffer, 0);
}
else return 0;
}
public static Int32 _Int32(Int64 Address)
{
if (System.Diagnostics.Process.GetProcessesByName(Pro cName).Length != 0)
{
IntPtr retByt; Byte[] buffer = new Byte[sizeof(Int32)];
ReadProcessMemory(pHandle, new IntPtr(Address), buffer, sizeof(Int32), out retByt);
return BitConverter.ToInt32(buffer, 0);
}
else return 0;
}
public static Int64 _Int64(Int64 Address)
{
if (System.Diagnostics.Process.GetProcessesByName(Pro cName).Length != 0)
{
IntPtr retByt; Byte[] buffer = new Byte[sizeof(Int64)];
ReadProcessMemory(pHandle, new IntPtr(Address), buffer, sizeof(Int64), out retByt);
return BitConverter.ToInt64(buffer, 0);
}
else return 0;
}
public static Single _Float(Int64 Address)
{
if (System.Diagnostics.Process.GetProcessesByName(Pro cName).Length != 0)
{
IntPtr retByt; Byte[] buffer = new Byte[sizeof(Single)];
ReadProcessMemory(pHandle, new IntPtr(Address), buffer, sizeof(Single), out retByt);
return BitConverter.ToSingle(buffer, 0);
}
else return 0;
}
public static String _String(Int64 Address, Int32 _Length)
{
if (System.Diagnostics.Process.GetProcessesByName(Pro cName).Length != 0)
{
IntPtr retByt; Byte[] buffer = new Byte[_Length];
ReadProcessMemory(pHandle, new IntPtr(Address), buffer, _Length, out retByt);
return ASCIIEncoding.ASCII.GetString(buffer);
}
else return "";
}
public static Byte[] _Bytes(Int64 Address, Int32 _Size)
{
if (System.Diagnostics.Process.GetProcessesByName(Pro cName).Length != 0)
{
IntPtr retByt; Byte[] buffer = new Byte[_Size];
ReadProcessMemory(pHandle, new IntPtr(Address), buffer, _Size, out retByt);
return buffer;
}
else return new byte[0];
}
}
}
}
5HV2X.png3 KB · 6 downloads ss (2013-12-10 at 02.24.52).png5 KB · 4 downloads
more like: copy and paste someone else's code, and when it doesnt work; paste the code on a forum and ask for help
do some work yourself. you will probably need to learn c# a little more
Quote Originally Posted by TrailerHooker View Post
more like: copy and paste someone else's code, and when it doesnt work; paste the code on a forum and ask for help
do some work yourself. you will probably need to learn c# a little more
Nice dude

But I made this post to get help and not an advice
Please learn to code, stop ripping off people's hardwork.
you are trying to read and write a string while the value is in fact an integer...

learn c# because data types is the basic (of basic of basic....) of all coding
You should have Googled, you could have found tons of examples how to fix the error.
Question for you: Is String same as Integer?
BTW, the address is too short.
Firstly thanks a lot for the help. When I set the type to Int32 or Int64 I get and error on all the line.

In this line, I'm gettin this error when I try to write Int32 or Int64, and the error say me that the arguments have to be (long, long):

(0x1444C2E40, squadpoints.Text);

If "squadpoints.Text" isn't a long, so how I write in an adress an amount of a TextBox?
the address is a long but you are getting a string returned by "textbox.text" so you have to convert that into a long/int

google it fork knowledge
Quote Originally Posted by distiny View Post
the address is a long but you are getting a string returned by "textbox.text" so you have to convert that into a long/int

google it fork knowledge
I tried it but I got an error when I opened the program "arithmetic operation resulted in an overflow", this line "ReadProcessMemory(pHandle, new IntPtr(Address), buffer, sizeof(Int64), out retByt);"

namespace COD_Squad_Points_Editor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

CC.ProcessName = "iw6mp64_ship";
label2.Text = CC.Read._Int64(0x1444C2E40).ToString();
}

private void btnapply_Click(object sender, EventArgs e)
{
long sp = Convert.ToInt64(squadpoints.Text);

CC.Write._Int64(0x1444C2E40, sp);
}
}
}
Quote Originally Posted by PvPlayer View Post
I tried it but I got an error when I opened the program "arithmetic operation resulted in an overflow", this line "ReadProcessMemory(pHandle, new IntPtr(Address), buffer, sizeof(Int64), out retByt);"
Compile it as a 64 bit application.
Quote Originally Posted by Lovroman View Post


Compile it as a 64 bit application.
Working now thanks! But there is another problem, the Currently SquadPoints is showing as 37531687 which should be 26 (the currently sp in my game). How I Fix it?
Quote Originally Posted by PvPlayer View Post
Working now thanks! But there is another problem, the Currently SquadPoints is showing as 37531687 which should be 26 (the currently sp in my game). How I Fix it?
Long is slightly too long .
Use normal Integer & you can convert text directly in the argument(you don't have to asign a new variable)
Quote Originally Posted by Lovroman View Post


Long is slightly too long .
Use normal Integer & you can convert text directly in the argument(you don't have to asign a new variable)
I'm trying it, but I didn't got it, can you see what is wrong?

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

CC.ProcessName = "iw6mp64_ship";

string antes = CC.Read._Int64(0x1444C2E40).ToString();
int depois = Convert.ToInt32(antes);

label2.Text = depois;
}

private void btnapply_Click(object sender, EventArgs e)
{
CC.Write._Int64(0x1444C2E40, Convert.ToInt64(squadpoints.Text));
}
}
Quote Originally Posted by PvPlayer View Post
I'm trying it, but I didn't got it, can you see what is wrong?
Code:
CC.Write._Int64(0x1444C2E40, Convert.ToInt64(squadpoints.Text));
to
Code:
CC.Write._Int32(0x1444C2E40, Convert.ToInt32(squadpoints.Text));
That's what I meant.
spoonfeeding time is over, start learning
Posts 1–15 of 17 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us