• Welcome to Valhalla Legends Archive.
 

MPQ Locale ID?

Started by Evan1993, May 15, 2008, 04:28 PM

Previous topic - Next topic

Evan1993

Oh, I saw he was using longs and in VB.net a long is 64 bits, sorry..

whats a better way to get a string to a hex(long)?

heres what I'm using right now.


Public Function StringToHex(ByRef Data As String) As Long
        'first take each charcter using substring.
        'then convert character into ascii.
        'then convert ascii value into Hex Format
        Dim sValue As String
        Dim sHex As String = ""
        Dim s As String = Data
        While s.Length > 0
            sValue = Conversion.Hex(Strings.Asc(s.Substring(0, 1).ToString()))
            s = s.Substring(1, s.Length - 1)
            sHex = sHex + sValue
        End While


        Return Long.Parse(sHex, NumberStyles.HexNumber)
    End Function

Hdx

Quote from: Evan1993 on May 16, 2008, 09:19 PMwhats a better way to get a string to a hex(long)?
Cleaner, Not always better, but use CopyMem

psudo:
Function ToInt32(value as string) as Integer
  Dim ret as Integer;
  CopyMemory(&ret, value, 4);
  ToInt32 = ret;
End Function

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

Evan1993

My IP in network byte order is 64 bits... how to I add it as a 32 bit integer?

Hdx

Convert it to a 32 bit int...
& 0xffffffff.
~Hdx

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

Evan1993

Quote from: Hdx on May 16, 2008, 09:56 PM
Convert it to a 32 bit int...
& 0xffffffff.
~Hdx
Well I was bing a retard again..
Public Declare Function inet_addr Lib "wsock32" (ByVal s As String) As Integer <--- was long before lolz

however i'm such a ninny that I don't get what you mean by "& 0xffffffff" do you mean
.InsertInt32(Integer.Parse(&HFFFFFFFF, NumberStyles.HexNumber))
?


Hdx

Quote from: Evan1993 on May 16, 2008, 10:10 PM
Quote from: Hdx on May 16, 2008, 09:56 PM
Convert it to a 32 bit int...
& 0xffffffff.
~Hdx
Well I was bing a retard again..
Public Declare Function inet_addr Lib "wsock32" (ByVal s As String) As Integer <--- was long before lolz

however i'm such a ninny that I don't get what you mean by "& 0xffffffff" do you mean
.InsertInt32(Integer.Parse(&HFFFFFFFF, NumberStyles.HexNumber))
?
When converting from a larger int to a smaller, and you don't give a fuck about the high-end. You do the binary and operation on the bits you want.
Hence & 0xffffffff will give you the low 32 bits of a 64 bit int

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

Ribose


using MBNCSUtil;
using System.Globalization;
[...]
        /// <summary>Sends packet 0x50, SID_AUTH_INFO.</summary>
        /// <param name="a_sProduct">The Product ID.</param>
        /// <param name="a_bVerbyte">The Version Byte.</param>
        private void Send_SID_AUTH_INFO(string a_sProduct, byte a_bVerbyte)
        {
            BncsPacket m_pbBncsPacket = new BncsPacket((byte) BattleNetPacketIDs.SID_AUTH_INFO);
            m_pbBncsPacket.InsertInt32(0x00);                                                       // (DWORD)  Protocol ID
            m_pbBncsPacket.InsertDwordString("IX86");                                               // (DWORD)  Platform Code
            m_pbBncsPacket.InsertDwordString(a_sProduct);                                           // (DWORD)  Product Code
            m_pbBncsPacket.InsertInt32((int) a_bVerbyte);                                           // (DWORD)  Version Byte
            m_pbBncsPacket.InsertInt32(CultureInfo.CurrentUICulture.LCID);                          // (DWORD)  Product Language
            m_pbBncsPacket.InsertInt32(0);                                                          // (DWORD)  Local IP
            m_pbBncsPacket.InsertInt32((int) DateTime.UtcNow.Subtract(DateTime.Now).TotalMinutes);  // (DWORD)  Timezone Bias
            m_pbBncsPacket.InsertInt32(CultureInfo.CurrentUICulture.LCID);                          // (DWORD)  Locale ID
            m_pbBncsPacket.InsertInt32(CultureInfo.CurrentUICulture.LCID);                          // (DWORD)  Language ID
            m_pbBncsPacket.InsertCString(RegionInfo.CurrentRegion.ThreeLetterISORegionName);        // (STRING) Country Abbreviation
            m_pbBncsPacket.InsertCString(RegionInfo.CurrentRegion.DisplayName);                     // (STRING) Country name
            SendPacket(m_pbBncsPacket.GetData());
        }

That's how you do it with C#.
Here's it in VB:

Imports MBNCSUtil
Imports System.Globalization
[...]
        ''' <summary>Sends packet 0x50, SID_AUTH_INFO.</summary>
        ''' <param name="a_sProduct">The Product ID.</param>
        ''' <param name="a_bVerbyte">The Version Byte.</param>
        Private Sub Send_SID_AUTH_INFO(ByVal Product As String, ByVal Verbyte As Byte)
            With (New BncsPacket(0x50))
                .InsertInt32(0x00)                                                       ' (DWORD)  Protocol ID
                .InsertDwordString("IX86")                                               ' (DWORD)  Platform Code
                .InsertDwordString(Product)                                              ' (DWORD)  Product Code
                .InsertInt32(CInt(Verbyte));                                             ' (DWORD)  Version Byte
                .InsertInt32(CultureInfo.CurrentUICulture.LCID);                         ' (DWORD)  Product Language
                .InsertInt32(0);                                                         ' (DWORD)  Local IP
                .InsertInt32(CInt(DateTime.UtcNow.Subtract(DateTime.Now).TotalMinutes))  ' (DWORD)  Timezone Bias
                .InsertInt32(CultureInfo.CurrentUICulture.LCID)                          ' (DWORD)  Locale ID
                .InsertInt32(CultureInfo.CurrentUICulture.LCID)                          ' (DWORD)  Language ID
                .InsertCString(RegionInfo.CurrentRegion.ThreeLetterISORegionName)        ' (STRING) Country Abbreviation
                .InsertCString(RegionInfo.CurrentRegion.DisplayName)                     ' (STRING) Country name
                SendPacket(.GetData())
            End With
        End Sub

Yea, I don't know how to get Local IP or whether all the values are gotten from the correct place... however that's a good way to construct a packet in .Net.

In .Net its:
Byte -> System.Byte (primitive type: VB Byte, C# byte)
Word -> System.Int16 (primitive type: VB Short, C# short)
DWord -> System.Int32 (primitive type: VB Integer, C# int)
LongLong (QWord) -> System.Int64 (primitive type: VB Long, C# long)
of course there are unsigned versions of all of those.
~Ribose

Ringo

Dunno if this helps:

Public Sub S_B_0x50(ByRef lngSckHdl As Long, _
                    ByRef lngClient As Long, _
                    ByRef lngVersionByte As Long, _
                    ByVal lngAddr As Long, _
                    ByRef hBuf As clsBuffer)
    Dim i           As Long
    Dim strCon      As String
    Dim strConAb    As String
    Dim lngCon      As Long
    Dim lngConAb    As Long
    Dim udtTimeZone As TIME_ZONE_INFORMATION
   
    '//Get the product language "enUS" (not "enGB")
    Call GetLocaleInfoA(GetSystemDefaultLCID(), &H59, lngCon, 4)
    Call GetLocaleInfoA(GetSystemDefaultLCID(), &H5A, lngConAb, 4)
   
    strCon = String(64, 0)
    strConAb = String(64, 0)
   
    '//GBR
    i = GetLocaleInfoA(GetUserDefaultLangID(), &H7, ByVal strConAb, Len(strConAb))
    strConAb = Left(strConAb, (i - 1))
    '//United Kingdom
    i = GetLocaleInfoA(GetUserDefaultLangID(), &H1002, ByVal strCon, Len(strCon))
    strCon = Left(strCon, (i - 1))
    '//Time Bias
    Call GetTimeZoneInformation(udtTimeZone)
   
    With hBuf
        .Clear
        .InsertDWORD &H0 'protocol id
        .InsertDWORD &H49583836 'IX86
        .InsertDWORD lngClient
        .InsertDWORD lngVersionByte
        .InsertMEM VarPtr(lngConAb), 2          'Product Language "US"
        .InsertMEM VarPtr(lngCon), 2            'Product Language "en"
        .InsertDWORD lngAddr                    'Local IP
        .InsertDWORD udtTimeZone.Bias           'TimeZone Bias
        .InsertDWORD GetUserDefaultLCID()       'Locale ID
        .InsertDWORD GetUserDefaultLangID()     'Language ID
        .InsertNTSTRING strConAb                'GBR
        .InsertNTSTRING strCon                  'United Kingdom
        .InsertHEADER &H50, BNCS_HEADER
        .SendPacket lngSckHdl
    End With
End Sub

Evan1993

My packet still looks wrong, does it change any when sent? Becuase I'm not sending it yet.

    Public Sub SendSendAuthInfo(ByVal Product As String)
        Dim AuthInfo As New BncsPacket(SID_AUTH_INFO)
        Dim time As TimeSpan = System.TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now)

        With AuthInfo
            .InsertInt32(&H0) 'Protocol ID
            .InsertDwordString("IX86") 'Platform ID
            .InsertDwordString(Product) 'Product ID
            .InsertInt32(CInt(MBNCSUtil.CheckRevision.GetVersionByte(Product))) 'Version Byte
            .InsertInt32(StringToHex(CultureInfo.CurrentCulture.Name.Remove(2, 1))) 'Product language
            .InsertInt32(CultureInfo.CurrentCulture.LCID) 'MPQ Locale ID
            .InsertInt32(inet_addr(System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList(0).ToString)) 'Local IP (in network byte order)
            .InsertInt32(time.TotalMinutes) 'Timezone bias
            .InsertInt32(CultureInfo.CurrentCulture.LCID) 'Language ID
            .InsertCString(Globalization.RegionInfo.CurrentRegion.ThreeLetterWindowsRegionName) 'Country Abbreviation
            .InsertCString(Globalization.RegionInfo.CurrentRegion.NativeName) 'Country
            AddChat(.ToString)
        End With

    End Sub


0 -Protocol ID
IX86 -Platform ID/code
W3XP -Product ID/code
21 -Product ID
enUS -Product language
1033 -MPQ Locale ID
117549248 -Local IP (in network byte order)
-240 -Timezone bias
1033 -Language ID
USA -Country Abbreviation
United States -Country


addchat shows:


0000   ff 50 3a 00 00 00 00 00  36 38 58 49 50 58 33 57    ÿP:.....68XIPX3W
0010   15 00 00 00 53 55 6e 65  09 04 00 00 c0 a8 01 07    ....SUne....À¨..
0020   10 ff ff ff 09 04 00 00  55 53 41 00 55 6e 69 74    .ÿÿÿ....USA.Unit
0030   65 64 20 53 74 61 74 65  73 00                      ed States.


Warcrafts..


0000  00 0f 66 30 22 b3 00 01  6c 19 d9 58 08 00 45 00   ..f0"... l..X..E.
0010  00 62 0f 71 40 00 80 06  00 00 c0 a8 01 07 3f f0   .b.q@... ......?.
0020  ca 83 0b 4f 17 e0 05 87  2d 03 de c1 e9 3f 50 18   ...O.... -....?P.
0030  ff ff cc 77 00 00 ff 50  3a 00 00 00 00 00 36 38   ...w...P :.....68
0040  58 49 50 58 33 57 15 00  00 00 53 55 6e 65 c0 a8   XIPX3W.. ..SUne..
0050  01 07 f0 00 00 00 09 04  00 00 09 04 00 00 55 53   ........ ......US
0060  41 00 55 6e 69 74 65 64  20 53 74 61 74 65 73 00   A.United  States.


Hdx

ff 50 3a 00 ÿP:. - (DWORD) Header
00 00 00 00 .... - (DWORD) Protocol ID (0)
36 38 58 49 68XI - (DWORD) Platform ID
50 58 33 57 PX3W - (DWORD) Product ID
15 00 00 00 .... - (DWORD) Version Byte
53 55 6e 65 SUne - (DWORD) Product language
09 04 00 00 .... - (DWORD) Local IP for NAT compatibility*
c0 a8 01 07 ˬ.. - (DWORD) Time zone bias*
10 ff ff ff .ÿÿÿ - (DWORD) Locale ID*
09 04 00 00 .... - (DWORD) Language ID*
55 53 41 00 USA. - (STRING) Country abreviation
55 6e 69 74 65 64 20 53 74 61 74 65 73 00 United States. - (STRING) Country


ff 50 3a 00 .P:. - (DWORD) Header
00 00 00 00 .... - (DWORD) Protocol ID (0)
36 38 58 49 68XI - (DWORD) Platform ID
50 58 33 57 PX3W - (DWORD) Product ID
15 00 00 00 .... - (DWORD) Version Byte
53 55 6e 65 SUne - (DWORD) Product language
c0 a8 01 07 .... - (DWORD) Local IP for NAT compatibility*
f0 00 00 00 .... - (DWORD) Time zone bias*
09 04 00 00 .... - (DWORD) Locale ID*
09 04 00 00 .... - (DWORD) Language ID*
55 53 41 00 USA. - (STRING) Country abreviation
55 6e 69 74 65 64 20 53 74 61 74 65 73 00   United States. - (STRING) Country

A few of your values are in the wrong order. Besides that your timezone is a bit messed up.

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

Evan1993

Heres my packet now, is it fixed?

ff 50 3a 00 ÿP:. - (DWORD) Header
00 00 00 00 .... - (DWORD) Protocol ID (0)
36 38 58 49 68XI - (DWORD) Platform ID
50 58 33 57 PX3W - (DWORD) Product ID
15 00 00 00 .... - (DWORD) Version Byte
53 55 6e 65 SUne - (DWORD) Product language
c0 a8 01 07 ˬ.. - (DWORD) Local IP for NAT compatibility*
f0 00 00 00 ð... - (DWORD) Time zone bias*
09 04 00 00 .... - (DWORD) Locale ID*
09 04 00 00 .... - (DWORD) Language ID*
55 53 41 00 USA. - (STRING) Country abreviation
55 6e 69 74 65 64 20 53 74 61 74 65  73 00 United States. - (STRING) Country



My timezone is 240 now, is that fixed?

        With AuthInfo
            .InsertInt32(&H0) 'Protocol ID
            .InsertDwordString("IX86") 'Platform ID
            .InsertDwordString(Product) 'Product ID
            .InsertInt32(CInt(MBNCSUtil.CheckRevision.GetVersionByte(Product))) 'Version Byte
            .InsertInt32(StringToHex(CultureInfo.CurrentCulture.Name.Remove(2, 1))) 'Product language
            .InsertInt32(inet_addr(System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList(0).ToString)) 'Local IP (in network byte order)
            .InsertInt32(DateTime.UtcNow.Subtract(DateTime.Now).TotalMinutes) 'Timezone bias
            .InsertInt32(CultureInfo.CurrentCulture.LCID) 'MPQ Locale ID
            .InsertInt32(CultureInfo.CurrentCulture.LCID) 'Language ID
            .InsertCString(Globalization.RegionInfo.CurrentRegion.ThreeLetterWindowsRegionName) 'Country Abbreviation
            .InsertCString(Globalization.RegionInfo.CurrentRegion.NativeName) 'Country
           
            AddChat(.ToString)
        End With


Hdx

looks good, send her off

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status