Sending Packets

11/09/2010 18:57 Interest07#91
C# code I use for packet sending as follows

PacketSender class:

use as follows:
PHP Code:
//open process
IntPtr pr_processHandle MemFunctions.OpenProcess(pid);
//create new packetSender class for this process
PacketSender sendPacket = new PacketSender(pr_processHandle);

//send packet for toggling flymode for example:
sendPacket.useItem(10xCplayer.values.flyMountId); 
Memfunctions class:

11/09/2010 19:07 Interest07#92
The packet sender class will store a packet in the process's memory when used for the first time, then at subsequent uses of a specific packet it will just writeMemory the new values into the packet at the correct positions.

The MemFunctions class contains some frequently used memory related functions (and DLL imports) which are used in the PacketSender class (and of course other classes i use :P).

The only addresses used frm the PWI_Offsets class are the base address and sendpacket function address, so you can just insert those as you see fit (for example pass to the class in the constructor).

The comments above the packets in the code aren't as detailed as in the autoIt code, so use that as a reference. Also in the end it says Regular Attack everywhere as I couldn't be bothered to update it anymore , what the packets do should be obvious from their names though hehe.

I personally use a PWprocess class that contains lists of all mobs / npcs / items / players and a packetsender, which would contain a closeHandle function call in the destructor and an openProcess function call in the constructor as in the packet sending example.


Standard disclaimer for my code:
Everything is probably functional and most likely not optimal in the efficiency department. Use at your own risk also :P
11/10/2010 06:23 sweetlady#93
Wow, sweet stuff Interest. Started building my SendPacket function today in C++. Not even sure it'd work but I'll start testing soon. I'll have a closer look at your C# classes and try to convert them to C++, althought I have to say I'm more of a beginner/intermediate c++ coder so far. But thank you. I'll keep you posted on my progress.
11/10/2010 08:44 silkytail#94
copypasted comments are funny :)
11/10/2010 09:56 Interest07#95
Quote:
Originally Posted by sweetlady View Post
Wow, sweet stuff Interest. Started building my SendPacket function today in C++. Not even sure it'd work but I'll start testing soon. I'll have a closer look at your C# classes and try to convert them to C++, althought I have to say I'm more of a beginner/intermediate c++ coder so far. But thank you. I'll keep you posted on my progress.
Hope it'll help you with that. It's been a long long time since I coded in C++, so I'm not sure if I can help you on that, but feel free to ask any questions :)

Quote:
Originally Posted by silkytail View Post
copypasted comments are funny :)
lol yeah they are :o



edit: fixed the header for one of the split stacks (should be 3C not 3B, as the previous entry was already 3B)

also, 3E0049 = flip while jumping
3E0048 = flip while running
11/11/2010 07:09 AEBus#96
Interest07, can you give any example of injection asm produce in c#?
11/11/2010 08:58 Interest07#97
The C# code on sending packets has inject code in it. I basically just throw the opcode i want to inject into a byte array, write that to the game's memory and run it. This is the part of the code above that handles the inject function. You pass the address of where the packet is loaded into the game's memory to the function with it's size. The sendpacket function then checks if it has already loaded the opcode into memory. If it hasn't it does so, else it writes the new packetAddress to the correct position and runs the opcode.

It will then remove the opcode again in the destructor of the class (so when you're done botting :P)

Code:
        private int sendPacketOpcodeAddress;
        private int packetAddressLocation;
        private int packetSizeAddress;

        //opcode for sending a packet
        private byte[] sendPacketOpcode = new byte[] 
        { 
            0x60,                                   //PUSHAD
            0xB8, 0x00, 0x00, 0x00, 0x00,           //MOV EAX, SendPacketAddress
            0x8B, 0x0D, 0x00, 0x00, 0x00, 0x00,     //MOV ECX, DWORD PTR [realBaseAddress]
            0x8B, 0x49, 0x20,                       //MOV ECX, DWORD PTR [ECX+20]
            0xBF, 0x00, 0x00, 0x00, 0x00,           //MOV EDI, packetAddress
            0x6A, 0x00,                             //PUSH packetSize
            0x57,                                   //PUSH EDI
            0xFF, 0xD0,                             //CALL EAX
            0x61,                                   //POPAD
            0xC3                                    //RET
        };


        private void loadSendPacketOpcode()
        {
            //Allocate memory for the opcode to call the sendPacket function
            sendPacketOpcodeAddress = MemFunctions.AllocateMemory(pr_processHandle, sendPacketOpcode.Length);

            //Write the opcode to memory
            MemFunctions.MemWriteBytes(pr_processHandle, sendPacketOpcodeAddress, sendPacketOpcode);

            //Insert the reverse baseAddress and sendPacketFunctionAddress in opcode
            byte[] functionAddress = BitConverter.GetBytes(SEND_PACKET_ADDRESS);
            functionAddress.Reverse();
            byte[] realBaseAddress = BitConverter.GetBytes(REAL_BASE_ADDRESS);
            realBaseAddress.Reverse();
            MemFunctions.MemWriteBytes(pr_processHandle, sendPacketOpcodeAddress + 2, functionAddress);
            MemFunctions.MemWriteBytes(pr_processHandle, sendPacketOpcodeAddress + 8, realBaseAddress);
            packetAddressLocation = sendPacketOpcodeAddress + 16;
            packetSizeAddress = sendPacketOpcodeAddress + 21;
        }

        public void sendPacket(byte[] packetLocation, int packetSize)
        {
            if (sendPacketOpcodeAddress == 0)
            {
                loadSendPacketOpcode();
            }

            MemFunctions.MemWriteBytes(pr_processHandle, packetAddressLocation, packetLocation);
            MemFunctions.MemWriteByte(pr_processHandle, packetSizeAddress, (byte)packetSize);

            //Run the opcode
            IntPtr threadHandle = MemFunctions.CreateRemoteThread(pr_processHandle, sendPacketOpcodeAddress);

            //Wait for opcode to be done
            MemFunctions.WaitForSingleObject(threadHandle);

            //Close the thread
            MemFunctions.CloseProcess(threadHandle);

        }
11/11/2010 09:45 AEBus#98
For example I need inject installation
and removal of certain navigation point
coordinates in the game, it can be
implemented through the send packets
function? and tell me how to do is
inject this?
11/11/2010 10:07 Interest07#99
As far as I know the navigation points are pure client based, so no, not with packets. I was simply giving an example on how to inject a function/asm.

Why would you want to insert navigation points though?
11/11/2010 10:37 AEBus#100
I want to make a kind of GPS navigator in the game, that at a certain point, this point was removed and was put out a new list of coordinates driven into a
text file
11/14/2010 03:40 khansa#101
Can you show complete the source code send packet gold in PW indo plese
11/14/2010 03:45 khansa#102
Quote:
Originally Posted by Smurfin View Post
tks, done changing and now it works, tried using it to drop 1 gold per x millisecond and it leaves gold trails when walk :D

is SkillId the same for every server ? do you have the list for cleric ?
Can you show complete the source code send packet gold in server PW indo? ( in autoit)
11/14/2010 08:40 Interest07#103
Look at the first post of this thread, it shows you exactly how to drop gold.
11/15/2010 04:55 khansa#104
>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "D:\My Documents\Downloads\Compressed\Test\test1.au3"
D:\My Documents\Downloads\Compressed\Test\test1.au3 (8) : ==> Error opening the file.:
#include <NomadMemory.au3>

>Exit code: 1 Time: 0.225

what wrong in this program???????????
11/15/2010 08:48 Interest07#105
you are missing the nomadMemory file in your autoIt Include folder.

I'll attach it for you (not sure if it's the most up to date one though, but it seems to work)