Playing a sound by command (lotf)

08/19/2015 10:36 zipquick#1
ive viewed a few other threads: [Only registered and activated users can see links. Click Here To Register...] [Only registered and activated users can see links. Click Here To Register...] [Only registered and activated users can see links. Click Here To Register...] [Only registered and activated users can see links. Click Here To Register...]
im still running into issues with the command. i know im doing something wrong. in one of the threads korvacs said you have to send 2 strings to play music. so i have
Code:
string[] Strings = new string[2];
                                            Strings[0] = "sound/blast.wav";
                                            Strings[1] = "1";
not sure how to fully do the command though. especially calling the string[]:
Code:
 if (Splitter[0] == "/sound")
                                        {
                                            string[] Strings = new string[2];
                                            Strings[0] = "sound/blast.wav";
                                            Strings[1] = "1";
                                            SendPacket(General.MyPackets.String(MyChar.UID, 20, ?)));
                                        }
heres the string packet:
Code:
public byte[] String(long CharId, byte Type, string name)
        {
            ushort PacketType = 1015;
            byte[] Packet = new byte[13 + name.Length];

            fixed (byte* p = Packet)
            {
                *((ushort*)p) = (ushort)Packet.Length;
                *((ushort*)(p + 2)) = (ushort)PacketType;
                *((uint*)(p + 4)) = (uint)CharId;

                *(p + 8) = Type;
                *(p + 9) = 1;
                *(p + 10) = (byte)name.Length;

                for (int i = 0; i < name.Length; i++)
                {
                    *(p + 11 + i) = Convert.ToByte(name[i]);
                }
            }

            return Packet;
        }
anyone know how to successfully do this?
08/19/2015 11:55 -impulse-#2
Code:
public unsafe byte[] String(long CharId, byte Type, params string[] data)
{
    ushort PacketType = 1015;
    int length = 0;
    foreach (var str in data)
        length += str.Length + 1;
    byte[] Packet = new byte[13 + length];

    fixed(byte* p = Packet)
    {

        *((ushort*)p) = (ushort)Packet.Length;
        *((ushort*)(p + 2)) = (ushort)PacketType;
        *((uint*)(p + 4)) = (uint)CharId;

        *(p + 8) = Type;
        *(p + 9) = (byte)data.Length;
        int offset = 10;
        foreach (var str in data)
        {
            var encoded = System.Text.Encoding.Default.GetBytes(str);
            *(p + offset++) = (byte)encoded.Length;

            //this
            for (int i = 0; i < encoded.Length; i++)
                *(p + offset++) = encoded[i];
            //or that
            //Buffer.BlockCopy(encoded, 0, Packet, offset, encoded.Length);
            //offset += encoded.Length;
        }
    }
    return Packet;
}
Then you can do
Code:
if (Splitter[0] == "/sound")
{
    string[] Strings = new string[2];
    Strings[0] = "sound/blast.wav";
    Strings[1] = "1";
    SendPacket(General.MyPackets.String(MyChar.UID, 20, Strings)));
}
08/19/2015 12:06 zipquick#3
Quote:
Originally Posted by -impulse- View Post
Code:
public unsafe byte[] String(long CharId, byte Type, params string[] data)
{
    ushort PacketType = 1015;
    int length = 0;
    foreach (var str in data)
        length += str.Length + 1;
    byte[] Packet = new byte[13 + length];

    fixed(byte* p = Packet)
    {

        *((ushort*)p) = (ushort)Packet.Length;
        *((ushort*)(p + 2)) = (ushort)PacketType;
        *((uint*)(p + 4)) = (uint)CharId;

        *(p + 8) = Type;
        *(p + 9) = (byte)data.Length;
        int offset = 10;
        foreach (var str in data)
        {
            var encoded = System.Text.Encoding.Default.GetBytes(str);
            *(p + offset++) = (byte)encoded.Length;

            //this
            for (int i = 0; i < encoded.Length; i++)
                *(p + offset++) = encoded[i];
            //or that
            //Buffer.BlockCopy(encoded, 0, Packet, offset, encoded.Length);
            //offset += encoded.Length;
        }
    }
    return Packet;
}
Then you can do
Code:
if (Splitter[0] == "/sound")
{
    string[] Strings = new string[2];
    Strings[0] = "sound/blast.wav";
    Strings[1] = "1";
    SendPacket(General.MyPackets.String(MyChar.UID, 20, Strings)));
}
thanks for the reply. still not working though for some reason. im not sure what is wrong. i type the command but nothing plays
08/19/2015 15:28 pro4never#4
You've actually updated the packet structure with his? Cause in yours you were telling the client that only 1 string was coming... It's a list of strings

# of strings

for # of strings
string length
string data

Your original packet structure was hardcoded to only send 1 string.
08/19/2015 15:42 -impulse-#5
Quote:
Originally Posted by pro4never View Post
You've actually updated the packet structure with his? Cause in yours you were telling the client that only 1 string was coming... It's a list of strings

# of strings

for # of strings
string length
string data

Your original packet structure was hardcoded to only send 1 string.
I updated the code to work with multiple strings, checked it for syntax errors only though.

Edit:
Try this code
Code:
public unsafe byte[] String(long CharId, byte Type, params string[] data)
{
    ushort PacketType = 1015;
    int length = 0;
    foreach (var str in data)
        length += str.Length + 1;
    byte[] Packet = new byte[13 + length];

    fixed(byte* p = Packet)
    {

        *((ushort*)p) = (ushort)Packet.Length;
        *((ushort*)(p + 2)) = (ushort)PacketType;
        *((uint*)(p + 4)) = (uint)CharId;

        *(p + 8) = Type;
        *(p + 9) = (byte)data.Length;
        int offset = 10;
        foreach (var str in data)
        {
            var encoded = System.Text.Encoding.Default.GetBytes(str);
            *(p + offset) = (byte)encoded.Length;
            Buffer.BlockCopy(encoded, 0, Packet, offset + 1, encoded.Length);
            offset += encoded.Length + 1;
        }
    }
    return Packet;
}
08/19/2015 17:11 pro4never#6
Quote:
Originally Posted by -impulse- View Post
I updated the code to work with multiple strings, checked it for syntax errors only though.

Yes, that's why I asked if he updated to using your packet structures as if he used just the 1 portion of your code and didn't notice you modified the structure then he'd be screwed.
08/19/2015 19:47 -impulse-#7
Quote:
Originally Posted by pro4never View Post
Yes, that's why I asked if he updated to using your packet structures as if he used just the 1 portion of your code and didn't notice you modified the structure then he'd be screwed.
You would have much more work to do if you were to do that than a simple copy paste.

He has yet to respond to my last update.
08/20/2015 00:20 zipquick#8
Quote:
Originally Posted by -impulse- View Post
You would have much more work to do if you were to do that than a simple copy paste.

He has yet to respond to my last update.
the updated code didn't work either sadly. i looked to cofture for a reference but still couldnt figure it out. do you know what the problem could be
08/20/2015 00:24 -impulse-#9
I don't. You should test the packet with some other data. For spouse name or guild ally or something. Check if it works.