1 more try...
I guess I didn't read most of your source code..here are a few comments/suggestions/things I do:
API
Code:
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAcess As UInt32, ByVal bInheritHandle As Boolean, ByVal dwProcessId As Int32) As IntPtr
Your subs Open and Hack are flawed. You don't actually check that OpenProcess was successful.
Also Hack returns True if the process isn't found :/ is opposite of what is normal/expected.
Also, check how the process name shows up in taskmanager (ctrl+alt+del) maybe you need .exe on the end? Easiest way is the window title (ie. caption, "AssaultCube")
maybe try finding the process by it's Window's Title (this isn't as good when the game is in multiple languages)
for Hack() try this..
Code:
If aProcess.MainWindowTitle. = "AssaultCube" Then
'found correct process, proceed.
End If
( I misread your post. I assumed the mem address you write to was for patching assembly code, but you're just trying to write a new value to your bullets. so the memory loc is probably writeable, that probably isn't the problem)
your Hack() function is weird: you return true when there is an error. This is the opposite of normal. Normally you return True on success. and false on failure.
was
Code:
Public Function Hack(ByVal Application As String) As Boolean
Dim pArray As Process() = Process.GetProcessesByName(Application)
If pArray.Length = 0 Then
Return True
End If
ReadProcess = pArray(0)
Open()
Return False
End Function
should be
Code:
''plz move API's and local variable (ie. m_hProcess and m_ReadProcess to top of class, so we know they exist beforehand. they're important enough :)
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAcess As UInt32, ByVal bInheritHandle As Boolean, ByVal dwProcessId As Int32) As IntPtr '
Public Function Hack(ByVal appWindowTitle As String) As Boolean
Dim pArray As Process() = Process.GetProcesses()
For each pp as Process in _pArray
If pp.MainWindowTitle.ToLower.Contains("assaultcube") Then ''hardcoded string for specific debuggin purposes. ignore appWindowTitle parameter for now
'found correct process.
m_ReadProcess = pp 'assume the game can not be running twice. some can/will. you may want another window with the same name!
m_hProcess = OpenProcess(Convert.ToUInt32(ProcessAccessType.PROCESS_VM_READ Or ProcessAccessType.PROCESS_VM_WRITE Or ProcessAccessType.PROCESS_VM_OPERATION), False, m_ReadProces*****)
If m_hProcess = IntPtr.Zero then
'open process failed. this is weird and normally doesn't happen. are you admin?
MessageBox.Show("OpenProcess Failed. Are you admin?")
return false
Else
'success. We can call rpm and wpm now!
Return True 'if we get here, OpenProcess worked. We should be ok to call WriteProcessMemory
End if
Next pp
''if we get here, the process wasn't found in the whole array of processes, we should return false
Return false ''its weird seeing this at the very end of a function. just how the logic is arranged sometimes. This happens when the user ran the hack without the game being open/fully logged in.
End Function
and change
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AC.Hack("ac_client")
AC.SetInt(&H4DF73C, Value:=1000)
End Sub
to
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
IF AC.Hack("AssaultCube") = True Then
'OpenProcess call successful. Ready to writebytes.
AC.SetInt(&H4DF73C, 1000) ' you should also check lpNumberOfBytesWritten to verify WriteProcessMemory wrote enough (all) bytes. it should work if OpenProcess worked
MessageBox.Show("Hack SUCCESS! bullets now == 1000 ?!")
Else
MessageBox.Show("Unable to attach to process. hmmm.") ' lol
End If
End Sub
'don't use Value:= when calling a function. I've used < 1 time. It might be some other language feature, not needed for a regular simple function call. Technically SetInt() is a Sub, you might want to rename it to WriteInt32 and make it return a value of success/fail if WriteProcessmemory fails when it's called. Should generally work 99% of the time though.
also, you may need to declare the ProcessAccessType as Uint32, I think default is Int32? maybe not important?
^^I could be wrong for 64 bit OS stuff, I don't have one so I can't test. This only tested on windows xp sp3 32 bit.
edit: In OpenProcess() I'm not 100% sure as to why, but inheritHandle ...ive always seen it set to false. you have 1. that might be important?! Try it as false --> and change the API declaration to expect a boolean, not an Integer
also: not sure if/why its correct, but it works for me: the third parameter of OpenProcess(), You don't have to convert proces***** to Uint. Leave it Int32.
Maybe in those last 2 comments, if you are on 64 bit, it might not be Int32 but just Integer (which for .net, on x64, is 64 bits not int32) Try it as what I have, and we'll go from there. What hardware/os are you on?
assuming this works, we need to add CloseHandle() to prevent a small memory leak cuz the OS thinks we still might use the handle eventually. we'll get to that if this even works for you.
I may download the game just to test if my personal code works haha.
-also, I've heard of some games that have more than 1 process, so sometimes you might not want the one that has a window (seems odd, the game makers do try to confuse us once in a while).
---------- Post added at 02:27 PM ---------- Previous post was at 02:06 PM ----------
changing the control structure a little (does the exact same thing: or should)
Code:
Public Function Hack(ByVal appWindowTitle As String) As Boolean
Dim pArray As Process() = Process.GetProcesses()
For each pp as Process in _pArray
If pp.MainWindowTitle.ToLower.Contains("assaultcube") Then ''hardcoded string for specific debuggin purposes. ignore appWindowTitle parameter for now
'found correct process.
m_ReadProcess = pp 'assume the game can not be running twice. some can/will. you may want another window with the same name!
Exit For 'don't keep checking other processes, we founds our already. Go to end of the loop and continue code execution there. (..loops)
Next pp
If m_ReadProcess = Nothing Then
'process not found.
Return False
Else
m_hProcess = OpenProcess(Convert.ToUInt32(ProcessAccessType.PROCESS_VM_READ Or ProcessAccessType.PROCESS_VM_WRITE Or ProcessAccessType.PROCESS_VM_OPERATION), False, m_ReadProces*****)
If m_hProcess = IntPtr.Zero then
'open process failed. this is weird and normally doesn't happen. are you admin?
MessageBox.Show("OpenProcess Failed. Are you admin?")
return false
Else
'OpenProcess success. We can call rpm and wpm now!
Return True
End if
End If
End Function
'more readable?
not sure if it matters but also change to this ('type As Uint32 after your struct name)
Code:
Private Enum MemoryAllocationProtectionType As UInt32
PAGE_NOACCESS = &H1
PAGE_READONLY = &H2
PAGE_READWRITE = &H4
PAGE_WRITECOPY = &H8
PAGE_EXECUTE = &H10
PAGE_EXECUTE_READ = &H20
PAGE_EXECUTE_READWRITE = &H40
PAGE_EXECUTE_WRITECOPY = &H80
PAGE_GUARD = &H100
PAGE_NOCACHE = &H200
PAGE_WRITECOMBINE = &H400
PAGE_CANREAD = PAGE_READONLY Or PAGE_READWRITE Or PAGE_EXECUTE_READ Or PAGE_EXECUTE_READWRITE
PAGE_CANEXECUTE = PAGE_EXECUTE Or PAGE_EXECUTE_READ Or PAGE_EXECUTE_READWRITE Or PAGE_WRITECOPY
PAGE_CANWRITE = PAGE_READWRITE Or PAGE_EXECUTE_READWRITE
End Enum
edit: if you can get it to compile and run, and tell me which msgbox() runs, I can maybe help you debug more.
(I downloaded game: ac_client 1.2, started CE, found "current clip count" after 2-3 tries of shot a bullet/update search amount. Found 2 address for 'current clip count.' I went with the first one. (can try second one later maybe)
added a new button to an existing bot project I have (99.99% just like the code I posted above)
Code:
Private Sub AttachToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AttachToolStripMenuItem.Click
If MEMMGR.Attach("AssaultCube") Then
DoOutput("Attach OK - ready.")
MEMMGR.WriteInt32(New IntPtr(Integer.Parse("08E5A72C", Globalization.NumberStyles.HexNumber)), 30) '30 is a good clip size
Else
DoOutput("Attach FAIL - unable to continue")
End If
End Sub
'works. Even if my original clip size was smaller than 30, apparently any int32 value written to that address will auto update-bullet count and max clip size -- No idea what kind of anti-cheat system (if any) the game uses!
^^ basically 2 lines of code: .Attach() and .WriteInt32.
the address will probably change every time the game loads, or probably even between map loads. There are ways to figure out which address it will be at. You also have to deal with aslr if you're on windows > xp. I <3 xp on my 2.8 pentium4 ht, 2g ram.