Direct Memory Access in Game

Adrain

Warlord
Joined
May 3, 2004
Messages
121
Location
UK
I posted this elsewhere originally but was gently reminded that that wasn't appropriate so I think this is the right place (If not then please advise and/or move to the correct one).

I have a request :

I've heard tell of one or more of the modders here who edit stuff within the RAM of CivIII itself as and when it's running. I've always made my amendments by tweaking the Saved Game files (An advantage of which being that if I b*lls-up then the file load fails and I know to discard those changes.) but it occurred to me that the idea of tweaking within the RAM of the program itself is actually quite an exciting idea.

Thus, I wonder if anyone could point me to where the software is to allow this, and perhaps a few starter tips on how to do things safely and not cr*p all over my system.

An added bonus would be that others may well, like me, find the idea exciting and learn something interesting.

An (Abbreviated) response from my original version was :
I have done some very preliminary explorations of that area, and hopefully that program is still somewhere on my hard drive, although I can't remember where I had it and my last search for it a couple weeks ago was unsuccessful. It used the Windows Debugging Functions API, notably the WriteProcessMemory function. That allows you to write data to memory locations of a running process, provided you've used the other appropriate debugging APIs to gain access to it. I've used it while logged in to an admin account (which may be important; not sure) on XP and 8.1.

The nice thing about modern versions of Windows is that they also have memory protection, so as long as you make sure you open the write process - Civ 3 - the only thing you can mess up is Civ 3. Though it's very possible to mess up and crash it.

Edit: Found it, and uploaded it here. The code quality is lower than I remembered and it doesn't do much yet, but it can provide a starting point.
 
Excuse my confusion. I was looking for an executable file in case I didn't make that clear. I don't have a setup for compiling code. My work is all in VBA within the context of Microsoft Office (Access / Excel / Word / Etc) which has its own development context exclusively for the VBA language. Would I find an executable if I dug further from your link? I looked quite carefully but found none.

You wouldn't. My investigation into this area never got beyond the experimental, proof-of-concept phrase, so I'd never previously uploaded it, and it was never "release ready." And I'm afraid the Windows APIs I used only work from C++, which is quite different from VBA.

It's also quite possible that you were recalling someone else's efforts, either before I joined or from a thread I missed. Antal1987 would be the likely suspect, but AFAIK his efforts only ever focused on executable patching, not memory modification. But I don't see every thread. The only other thing I can think of, which I've never looked into, is perhaps there were "trainer" programs that worked this way back in the day, but that's probably not quite what you are thinking of.

Well, one other thing. If you like to live life on the edge, the HxD hex editor is what I used when first exploring this, as it lets you view a process's memory and write to it (Tools menu -> Open Main Memory). It isn't tailored to Civ at all, and the user friendliness is low (though not bad for a hex editor), but combined with sufficient knowledge of the SAV format, it can be used for this task. Not recommended but as an example, if you search for "PRTO_Warrior", you'll probably find the Warrior part of the BIQ in memory (it can take a few minutes to search, be patient), and you could overwrite the name to "Clubman" and it should show up in game. It's too clunky for extensive changes, however.

Again though, if someone else knows about something convenient, I'd be interested to hear about it.
 
You're very kind to find this for me Quintillus. I remember reading it somewhere on this site but I'm really not sure where. Certainly it was in an area discussing modding - I seem to recall the poster assumed that all such tweaking would be done using in-game RAM, however it was totally new to me.

I do have, what I consider to be, a pretty thorough understanding of the SAV file format. Most of my modding energies have been in that direction. So, I will certainly give the HxD hex editor a go. I'm quite excited to explore as it happens. I'll post an update once I know more about it. The main usage for me I suspect will be to discover more detail about what's stored where. Play "What if I change this?" and see what happens. It can be done by editing the SAV file and reloading but could be a lot quicker and more immediate this way.
 
Wow. That is simply awesome. Much of the data is held very differently in-game compared to the SAV file unfortunately, but not all certainly.

The very idea of accessing the memory while the program is open is just so fantastic. I have used DEBUG before, and other debuggers (I used to work in c & Assembler etc back in pre-history.), but to have it so easily accessible without even pausing the process is not something I expected to be possible. I anticipate veritable hours of fun :-)
 
antal1987 did run-time decompiling. Someone (meaning, "Me" :rolleyes: ) should probably compile together his various notes. That being said, he did put all of the framework info he used for his fine patches "NoRaze," etc., up on GitHub - https://github.com/Antal1987/C3CPatchFramework
 
Back
Top Bottom