Author | Message | Time |
---|---|---|
LockesRabb | 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 [code]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[/code] Edit: Gave credit to Drakken and OverFlow. I'm decent, ain't I? ;-) | July 7, 2005, 1:59 AM |
laurion | 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? | July 7, 2005, 2:15 AM |
LockesRabb | 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. | July 7, 2005, 2:21 AM |
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). | July 7, 2005, 2:23 AM |
KkBlazekK | [quote] Private lpWnd, lpId, lpHandle As Long [/quote] 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 | July 7, 2005, 2:36 AM |
LockesRabb | [quote author=Kp link=topic=12122.msg119378#msg119378 date=1120702995] 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). [/quote] KP: Atomically? Do you mean automatically? [quote author=Blaze link=topic=12122.msg119380#msg119380 date=1120703807] [quote] Private lpWnd, lpId, lpHandle As Long [/quote] 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] Blaze: Option Explicit's added now. Thanks. <<Edit: Instead of double-posting to reply to Blaze, I added reply here.>> | July 7, 2005, 2:43 AM |
Kp | [quote author=Kyro link=topic=12122.msg119382#msg119382 date=1120704193][quote author=Kp link=topic=12122.msg119378#msg119378 date=1120702995]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).[/quote]KP: Atomically? Do you mean automatically?[/quote] No, I mean atomically, which is why I wrote atomically. | July 7, 2005, 3:08 AM |
LockesRabb | What is atomically? | July 7, 2005, 3:12 AM |
dRAgoN | [code]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[/code] 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. | July 7, 2005, 6:41 AM |
LivedKrad | [quote author=Kyro link=topic=12122.msg119388#msg119388 date=1120705959] What is atomically? [/quote] Probably has something to do with the atomic clock. | July 7, 2005, 12:15 PM |
dRAgoN | [code]Private Const SC_Clock = &H13F8C4[/code] Mind you the clock dosent look very far off from gtc. | July 7, 2005, 4:59 PM |