Jump to content
  • Advertisement
Sign in to follow this  
Deathscythe_HC

LoadLibrary() remplacement

This topic is 3670 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey! I really hit a big snag and I was hoping some of you could help me! I'm currently working on the AI manager part of my game engine. I want to implement my own version of the LoadLibrary() function. Let me explain: AI source code are derived classes (from AIResource for example) in CPP files (1 derived class per file). The resource manager calls the compiler of Visual C++ to create the appropriate OBJ file (COFF) (no linking). Then, it fixes the code relocations with the MAP file from the game engine to create an AI resource file containing the final data ( .data, .bss, .text sections, etc. ). The AI manager, when the AI is required, loads the resource file, create a memory buffer for the instance data. But, here comes the problem. How do I load the different sections into virtual memory? How do I link the instance buffer to be used as the storage buffer for the AI class members? I guess VirtualAlloc(), VirtualProtect() and similar API functions are a part of the answer but there is not much information about this kind of procedure. The majority of texts talk about DLL loading and DLL injections. And any information about the .debug$ sections of the COFF file will be also appreciated. Implementing some way to debug AI code will be needed.

Share this post


Link to post
Share on other sites
Advertisement
Writing a LoadLibrary() routine that is as safe or as effective as the current implementation is hard and difficult. However it has been done before and is known as ManualMap in the hacking community. Here is a link to one of the many sites where it's source is stored. http://www.battleforums.com/forums/diablo-hacking/104572-release-manualmap-cpp-even-more-protection.html

That example does have a bug with dll forwarding and another in the implementation, but it does show you how to manual map a dll into memory. You might also be interested in the DIA SDK (Debug Information Access SDK)

Share this post


Link to post
Share on other sites
im not a total pro in programming but there still some things i dont understand. One being this topic. I want to ask why do you want to do this/that? What different about that then regular file loading? I think i know the answer to the last one just making sure.

Share this post


Link to post
Share on other sites
Quote:
Original post by owiley
im not a total pro in programming but there still some things i dont understand. One being this topic. I want to ask why do you want to do this/that? What different about that then regular file loading? I think i know the answer to the last one just making sure.


I want to port my engine on multiple platforms and that includes consoles where there is no native DLL-like support and I don't want to recompile the engine each time the AI source code is modified. The AI code will be loaded and executed only when needed. This will also allow AI hot-swapping without the game engine being restarted after updates.

Share this post


Link to post
Share on other sites
A clarification to what I want to do. Beside replacing LoadLibrary(), I want to do the linking dynamically. The AI resource is NOT a DLL. It is just a modified COFF file (*.obj) where relocations are fixed. So the only things it has are the .text, .bss, .rdata, .data and other necessary sections. I want to find a way to append those sections to the engine on the fly.

Share this post


Link to post
Share on other sites
Quote:
Original post by Barius
Couldn't you just use a scripting language like Lua for your AI?


A script engine has too much overhead for my liking and I would need to implement the bridge between the engine and the script. And I do not want a part of my engine to be dependent of something else because of debugging & portability issues.

Share this post


Link to post
Share on other sites
Quote:
Original post by rofseek
Writing a LoadLibrary() routine that is as safe or as effective as the current implementation is hard and difficult. However it has been done before and is known as ManualMap in the hacking community. Here is a link to one of the many sites where it's source is stored. http://www.battleforums.com/forums/diablo-hacking/104572-release-manualmap-cpp-even-more-protection.html

That example does have a bug with dll forwarding and another in the implementation, but it does show you how to manual map a dll into memory. You might also be interested in the DIA SDK (Debug Information Access SDK)


Thanks! Even though it is for DLLs, it explains how to load sections into the process. Now, just to find out how to map the AI functions. How do I setup the base class pointers to those loaded AI ( they're derived from a base class containing 4 virtual functions: Init, Process, Release and the destructpr )?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!