• Welcome to Valhalla Legends Archive.
 

Display Function no longer working

Started by Don Cullen, July 06, 2005, 08:59 PM

Previous topic - Next topic

Don Cullen

For some reason, Starcraft erases the first character of whatever message my program writes to its memory. I'm going crazy trying to figure out why this is happening, hopefully you'll have better luck than I am having...

When the program writes the text to SC's memory, the first character in the string gets erased- SC's way of removing text from screen *or* preventing text from being displayed (if first char is null, sc does not display).

Here's the code. Credit goes to Drakken for his tutorial, and OverFlow636 for pointing me in the right direction, and myself. :-P

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, ByVal lpNumberOfBytesWritten As Long) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function VirtualProtectEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long

Private Const GAME_STATE As Long = &H645E54
Private Const PAGE_EXECUTE_READWRITE = &H40&
Private Const PAGE_READONLY = &H2&
Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF

Private lpWnd, lpId, lpHandle As Long
Private bGameActive As Boolean

Public Const Blue = 2
Public Const Yellow = 3
Public Const White = 4
Public Const DarkGrey = 5
Public Const Red = 6
Public Const Green = 7
'

Public Sub SendSCMsg(text As String, delay As Long, color As Integer)
   
    Dim nex As Long
    Dim viewvar As Long
    Dim buff As Long

    'gets the number of the next address to write
    ReadProcessMemory lpHandle, &H659174, nex, 1, 0&
    viewvar = Asc(nex)
   
    'sets up how long we want our message up for
    buff = GetTickCount() + delay
   
    'writes some time to starcraft for our message
    WriteDWORD &H659140 + (viewvar * 4), buff
   
    'writes the text to go with that time
    text = Chr(color) & text & Chr(0)
    WriteProcessMemory lpHandle, CurTxtAddy(nex), text, Len(text), &H0
   
    'increment the address number so sc doesnt think nothing is there
    nex = nex + 1
    If nex = &HB Then nex = &H0
    WriteMem &H659174, Hex(nex)
End Sub

Private Function CurTxtAddy(Slot As Long) As Long
    If Slot = &H0 Then
        CurTxtAddy = &H658EB0
    ElseIf Slot = &H1 Then
        CurTxtAddy = &H65862C
    ElseIf Slot = &H2 Then
        CurTxtAddy = &H658706
    ElseIf Slot = &H3 Then
        CurTxtAddy = &H6587E0
    ElseIf Slot = &H4 Then
        CurTxtAddy = &H6588BA
    ElseIf Slot = &H5 Then
        CurTxtAddy = &H658994
    ElseIf Slot = &H6 Then
        CurTxtAddy = &H658A6E
    ElseIf Slot = &H7 Then
        CurTxtAddy = &H658B48
    ElseIf Slot = &H8 Then
        CurTxtAddy = &H658C22
    ElseIf Slot = &H9 Then
        CurTxtAddy = &H658CFC
    ElseIf Slot = &HA Then
        CurTxtAddy = &H658DD6
    End If
End Function

Public Function WriteDWORD(Address As Long, DataToWrite As Long)
    Dim buf As String
    buf = Hex(DataToWrite)

    Do While Not Len(buf) = 8
        buf = "0" & buf         'put NEEDED zeros in
    Loop
   
    WriteMem Address + 3, Mid(buf, 1, 2)
    WriteMem Address + 2, Mid(buf, 3, 2)
    WriteMem Address + 1, Mid(buf, 5, 2)
    WriteMem Address, Mid(buf, 7, 2)
End Function

Public Function WriteMem(Address As Long, DataToWrite As String)
    If Len(DataToWrite) = 1 Then DataToWrite = "0" & DataToWrite
    leng = Len(DataToWrite) / 2
    For i = 1 To leng
        WriteProcessMemory lpHandle, Address, Chr$("&H" & Left(DataToWrite, 2)), 1, gg
        Address = Address + 1
        DataToWrite = Right(DataToWrite, Len(DataToWrite) - 2)
    Next
End Function


Edit: Gave credit to Drakken and OverFlow. I'm decent, ain't I? ;-)
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

Tazo

#1
Why not just put a char you dont care if it gets erased?
I'm assuming it has something to do with the new patch  :-\
example: SendToBw, "AHi"
A would be erased, but who cares?

Don Cullen

actually, if the first char gets erased, SC will *not* display ANY of the message, because erasing the first char of the msg is sc's way of preventing the text from being displayed. doesn't matter what char is put there.

And yes, it changed due to the 1.13 patch.
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

Kp

I'd hazard a guess that you're not setting the timeout correctly, so Starcraft immediately classifies the message as "very old" and blanks out the first character to erase the message.  Try setting the timestamp atomically (ideally atomically with respect to the text itself).
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Blaze

Quote
Private lpWnd, lpId, lpHandle As Long
I didn't think vb allowed that... try putting in a option explicit at the top...

Note: this is just for the codes overall goodness, not for fixing the problem
Quote
Mitosis: Haha, Im great arent I!
hismajesty[yL]: No

Don Cullen

#5
Quote from: Kp on July 06, 2005, 09:23 PM
I'd hazard a guess that you're not setting the timeout correctly, so Starcraft immediately classifies the message as "very old" and blanks out the first character to erase the message.  Try setting the timestamp atomically (ideally atomically with respect to the text itself).

KP: Atomically? Do you mean automatically?

Quote from: Blaze on July 06, 2005, 09:36 PM
Quote
Private lpWnd, lpId, lpHandle As Long
I didn't think vb allowed that... try putting in a option explicit at the top...

Note: this is just for the codes overall goodness, not for fixing the problem

Blaze: Option Explicit's added now. Thanks.

<<Edit: Instead of double-posting to reply to Blaze, I added reply here.>>
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

Kp

Quote from: Kyro on July 06, 2005, 09:43 PM
Quote from: Kp on July 06, 2005, 09:23 PMI'd hazard a guess that you're not setting the timeout correctly, so Starcraft immediately classifies the message as "very old" and blanks out the first character to erase the message.  Try setting the timestamp atomically (ideally atomically with respect to the text itself).
KP: Atomically? Do you mean automatically?

No, I mean atomically, which is why I wrote atomically.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Don Cullen

Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

l)ragon

#8
Private Function CurTmrAddy(Slot As Byte) As Long
    If Slot = &H0 Then
        CurTmrAddy = &H659168
    ElseIf Slot = &H1 Then
        CurTmrAddy = &H659140
    ElseIf Slot = &H2 Then
        CurTmrAddy = &H659144
    ElseIf Slot = &H3 Then
        CurTmrAddy = &H659148
    ElseIf Slot = &H4 Then
        CurTmrAddy = &H65914C
    ElseIf Slot = &H5 Then
        CurTmrAddy = &H659150
    ElseIf Slot = &H6 Then
        CurTmrAddy = &H659154
    ElseIf Slot = &H7 Then
        CurTmrAddy = &H659158
    ElseIf Slot = &H8 Then
        CurTmrAddy = &H65915C
    ElseIf Slot = &H9 Then
        CurTmrAddy = &H659160
    ElseIf Slot = &HA Then
        CurTmrAddy = &H659164
    End If
End Function


Delay offsets

Edit: If it wasent for Slot 0 you could have been useing
eg.
BaseOffset = SlotOffset + (slot * 218) for the text
BaseOffset = SlotOffset + (slot * 4) for the timer
Edit#2: screwed 1 of the offsets set fine now.
*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*ˆ¨¯¯¨ˆ*^~·.,l)ragon,.-·~^*ˆ¨¯¯¨ˆ*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*

LivedKrad

Quote from: Kyro on July 06, 2005, 10:12 PM
What is atomically?

Probably has something to do with the atomic clock.

l)ragon

Private Const SC_Clock = &H13F8C4
Mind you the clock dosent look very far off from gtc.
*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*ˆ¨¯¯¨ˆ*^~·.,l)ragon,.-·~^*ˆ¨¯¯¨ˆ*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*