• Welcome to Valhalla Legends Archive.
 

Parsing the colors

Started by Networks, May 04, 2004, 08:58 AM

Previous topic - Next topic

MyndFyre

Quote from: Networks on May 10, 2004, 08:58 AM
Just curious but when sending: ÁQ Hi Hello
Should it be coloring just "hi" or the whole sentence?

My point about not having to "replicate" exactly the bug is that people are trying for a certain behavior here.  I would implement it so that the color went for the whole line, until the next color definition.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Eli_1

Feature! It's a feature damnit!

ChR0NiC

#62
Not to mention a very sexy feature

Edit: I went ahead and added this feature to my bot even, because it's just that sexy.

Networks

Well I guess it's not so much of a bug anymore if bnet to patch it.

Eli_1

This feature shall live on... Regardless...

DarkMinion

Nice avatar, dickless.  Angelfire doesn't allow off-site linking.

At any rate, I figured I'd post a C++ version for you who aren't stuck in the dredges of VB:


   char *pPtr = strtok(szTxtToAppend, "Á");
   while(pPtr != NULL){
      switch(pPtr[0]){
         case 'Y':
            AppendText(RED, pPtr + 1);
            break;
         case 'U':
            AppendText(CYAN, pPtr + 1);
            break;
         case 'R':
            AppendText(YELLOW, pPtr + 1);
            break;
         case 'V':
            AppendText(GREEN, pPtr + 1);
            break;
         case 'Z':
            AppendText(PURPLE, pPtr + 1);
            break;
         default:
            AppendText(Color, pPtr);
            break;
      }
      pPtr = strtok(NULL, "Á");
   }

shadypalm88

I've heard that SC/BW messages are encoded using Unicode, but I've never had to do anything special for it.  I wrote my own little function to handle this and when I tried running it with fooÁUbar to test, instead my bot showed fooÃ?Ubar, with that little square between the à and ?U that is shown for unrecognised characters.  Taking a hex dump of the message (66 6F 6F C3 81 55 62 61 72) suggests that 2 bytes are being sent to represent the accented A.  Is this, in fact, wide-character encoding, and if so how can I convert it?

Networks

I believe that happens when you in the actual starcraft client, not on some bot. I guess it just doesn't work when your on the game and sending messages in unicode. You might want to just hit Clan Recruitment and test it =p.

shadypalm88

#68
Just ran a test, and here's what letters produce what colors:

ÁA-ÁO: (no effect)
ÁQ: gray
ÁR: green
ÁS, ÁX, ÁZ: yellow
ÁT, ÁU, ÁV: blue
ÁP, ÁW: white
ÁY: red

And here's the VB function I use to translate the color codes into actual colors.  It also supports a default color that you can pass if the color code is not recognised.Private Function SCColorToVBColor(ColorCode As String, Optional ByVal Default& = vbWhite) As Long
   Select Case ColorCode
       Case "Y": SCColorToVBColor = vbRed
       Case "U", "T", "V": SCColorToVBColor = vbCyan
       Case "S", "X", "Z": SCColorToVBColor = vbYellow
       Case "R": SCColorToVBColor = vbGreen
       Case "P", "W": SCColorToVBColor = vbWhite
       Case "Q": SCColorToVBColor = &H808080
       Case Else: SCColorToVBColor = Default
   End Select
End Function

Blaze

#69
Can you post your addchat that you use with that or show me and example on how to use it?

btw, shouldn't your function include the A character?
Quote
Mitosis: Haha, Im great arent I!
hismajesty[yL]: No

Eli_1

#70
Lol come on man, code for all of this has already been posted. All he posted was the GetColor function, which was already posted, with the correct colors.

Here -- it's the second post down, by me.

Skywing

Quote from: shadypalm88 on May 11, 2004, 09:48 PM
I've heard that SC/BW messages are encoded using Unicode, but I've never had to do anything special for it.  I wrote my own little function to handle this and when I tried running it with fooÁUbar to test, instead my bot showed fooÃ?Ubar, with that little square between the à and ?U that is shown for unrecognised characters.  Taking a hex dump of the message (66 6F 6F C3 81 55 62 61 72) suggests that 2 bytes are being sent to represent the accented A.  Is this, in fact, wide-character encoding, and if so how can I convert it?
Look for information about UTF-8.  Blizzard uses a (broken) UTF-8 encoding implementation that allows redundant encodings.

There are many redundant encodings for those characters, not just the most commonly seen one.

Be careful about implementing this bug, because there are lots of things you probably don't want appearing in the middle of your text (e.g. nulls, newlines, and so on).

shadypalm88

Well, someone did ask for it, so here's my AddChat function that supports SC colors.  It works differently than others posted here since it does not use Split(), which seemed to me like it wouldn't work properly if the message didn't start with a color.  This sub also handles non-colored messages just fine.

The arguments it takes:
sText: Any text you want placed before the message.  You can use this to show the person's username.
sColor: The color to be applied to sText.
Message: The message that someone on B.net sent that you would like to display.
mColor: The default color to apply to Message.
eText: Optional text to tack on to the end of the message.  Uses the same color as the starting text.

And here it is:Public Sub AddC_SCColors(sText As String, sColor As Long, ByVal Message As String, _
   mColor As ColorConstants, Optional eText As String = "")
   '-----------------------------------------------------'
   ' From Myriad 1.0 Private Alpha                       '
   ' By Cloaked                                          '
   '-----------------------------------------------------'
   Dim i&, L&, CC As Long, ct As String, cChar As String
   'Do some initializing.
   i = 1
   L = Len(Message)
   ct = ""
   CC = mColor
   
   With frmMain.rtbChannel
       'Timestamp
       .SelStart = Len(.Text)
       .SelLength = 0
       .SelColor = vbWhite
       .SelText = "[" & Format(Time, "h:mm:ss AM/PM") & "] "

       'Starting text
       .SelStart = Len(.Text)
       .SelLength = 0
       .SelColor = sColor
       .SelText = sText
   End With
   
   'Main message loop
   While i <= L
       cChar = Mid$(Message, i, 1)
       If cChar = "Á" Then
           'Color detection
           With frmMain.rtbChannel
               .SelStart = Len(.Text)
               .SelLength = 0
               .SelColor = CC
               .SelText = ct
           End With
           ct = ""
           i = i + 1
           CC = SCColorToVBColor(Mid$(Message, i, 1), sColor)
       ElseIf Mid$(Message, i, 2) = "Ã?" Then
           'Crude support for the accented A represented in UTF-8 (?)
           With frmMain.rtbChannel
               .SelStart = Len(.Text)
               .SelLength = 0
               .SelColor = CC
               .SelText = ct
           End With
           ct = ""
           i = i + 2
           CC = SCColorToVBColor(Mid$(Message, i, 1), sColor)
       Else
           ct = ct & cChar
       End If
       i = i + 1
   Wend
   With frmMain.rtbChannel
       'Flush what's left in the message buffer
       .SelStart = Len(.Text)
       .SelLength = 0
       .SelColor = CC
       .SelText = ct
       'Add newline characters
       If Len(eText) = 0 Then
           eText = vbCrLf
       Else
           eText = eText & vbCrLf
       End If
       'Add ending text
       .SelStart = Len(.Text)
       .SelLength = 0
       .SelColor = sColor
       .SelText = eText
   End With
End Sub

Noodlez

#73
Your AddChat function is unneccesarily bloated. You can accomplish the same functionality with
Public Sub AddChat(ParamArray saElements() As Variant)
   Dim strTimeStamp As String, As Boolean, Data As String
   If BotData.GUI.Timestamp = True Then
       strTimeStamp = "[" & Format$(Time, "hh:mm:ss") & "]  "
   End If
   Dim i As Integer
   For i = LBound(saElements) To UBound(saElements) Step 2
       With frmMain.rtbChat
           .SelFontName = GUI.FontName
           .SelFontSize = GUI.FontSize
           .SelStart = Len(.Text)
           .SelLength = 0
           .SelColor = saElements(i)
           .SelText = saElements(i + 1) & Left$(vbCrLf, -2 * CLng((i + 1) = UBound(saElements)))
           .SelStart = Len(.Text)
           Data = Data & saElements(i + 1)
       End With
   Next i

End Sub


You call it like so

AddChat Color, Text, Color, Text, _

Easy to implement with that SC to VB color function.

DarkMinion

Updated for you sane C++ users


   char *pPtr = strtok(szTxtToAppend, "Á");
   while(pPtr != NULL){
      switch(pPtr[0]){
         case 'Q':
            AppendText(GRAY, pPtr + 1);
            break;
         case 'R':
            AppendText(GREEN, pPtr + 1);
            break;
         case 'S':
         case 'X':
         case 'Z':
            AppendText(YELLOW, pPtr + 1);
            break;
         case 'T':
         case 'U':
         case 'V':
            AppendText(LIGHTBLUE, pPtr + 1);
            break;
         case 'P':
         case 'W':
            AppendText(WHITE, pPtr + 1);
            break;
         case 'Y':
            AppendText(GRAY, pPtr + 1);
            break;
         default:
            AppendText(Color, pPtr);
            break;
      }
      pPtr = strtok(NULL, "Á");
   }

|