Now that we have the correct addresses for the linux and windows binaries, we will write a program to edit these values during run time. You will want to download the cof plugin’s source to follow along with the examples I provide.
Although the source plugin is very stripped down, there is still a lot going on. I will be citing specific examples inside the file and explaining what it does, there is not really any need to know what anything else does. Also, instead of trying to merge this file with an existing plugin, I will have you work in a brand new server plugin provided by valve in the source sdk. It is called serverplugin_sample in the source sdk. If you do not have the source sdk, then please download the project here.
What we are going to do first is write our mod directly to a hard coded address. In the future I will talk about sigs and scanning and all that, but for a first run this is fine. There are two functions you should familiarize yourself with, and thats VirtualProtect and memcpy. What I understand virtual protect to do, and this was explained to me by someone online, is that it protects an address space from being paged in such a way that memcpy will cause your program to break. From my understanding, virtual protect will force an address to exist in memory while you write to it. If you do not use virtual protect you run the risk of writing memory into the wrong location. Windows is constantly swapping memory in and out of ram to accommodate large programs, and by protecting that address space you guarantee yourself a safe write.
So, to write your shot code directly into the game, add this into the Plugin::Load function.
VirtualProtect([address], 10, PAGE_EXECUTE_READWRITE, &dwBack );
memcpy([address], 0×00000000, size);
memcpy([address]+5, 0×00000000, size);
VirtualProtect([address], 10, dwBack, &dwBack)
You can see an example of this in the writeMemory function of my source code example. dwBack stores the previous access permission for the address, after you write the code using memcpy, just feed dwBack to virtual protect to reset the permissions. [address] is the address you found the correct shot code at. Use the address right after 68 in the hex file. This code will replace 680000803F68000080BF with 68000000006800000000. Doing the same thing you just did with the hex editor, but this time actually doing it at run time.
Make sure to delete the binaries you edited with the hex editor before running the game with this plugin. You want to make sure this works right? When alls said and done you should end up with the same result as the hex edited binaries in a server plugin.
Next time I will show you how to use sigs to scan for the correct address, rather then hard code it and have it break at the first update.


Recent Comments