Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Hey everyone! Today I wanted to talk about something pretty cool - DLL libraries, and specifically how to integrate new JavaScript functions into a CopperCube game. For the past few weeks, I’ve been digging into CopperCube from the inside: debugger, hex editor, and lots of C++ code - all in an attempt to inject code into the game process via DLLs. But just a few days ago, I stumbled upon something interesting. A lot of CopperCube users publish their games on itch.io, which means for many of us the steamwrapper.dll library is completely irrelevant. And here’s the fun part - instead of going through the usual injection method (which is what I normally do), you can simply rename your own DLL to steamwrapper.dll and it will automatically get loaded by the game. That way, you can run the game straight from the engine while having your custom library loaded, which means you can debug the game with your DLL already in place. Right now, I’m still running into some problems, like not being able to get irr::IrrlichtDevice - which is a tough one, because it’s one of the most important classes. But at this point I can hook up a gamepad, change the game window size at runtime, and do a few extra file-handling tricks - all of which are integrated into JavaScript, letting me easily call functions and variables that the DLL registers. So yeah, the point of this post is: if there’s anyone here working with the game’s source code, just keep in mind that DLL injection and/or library swapping is actually a pretty solid way to expand your game’s capabilities. |
||||
|
Can you make a video tutorial explaining the DLL? |
||||
|
Yeah, do a video - I would interested in having a look how you did that actually. You can get access to the irlichtDevice in the C++ source code: CPlayer.cpp 'Device->getVideoDriver()' or CPlayerScriptLib.cpp LastPlayer->Scripting->getIrrlichtDevice() there may be other ways also....in the c++ files |
||||
|
I’m not really covering video creation since I’m super antisocial, but I can briefly explain the principle. Start simple: open the compiled exe from the CopperCube engine in whatever tool you’re comfortable with (IDA, Ghidra, or whatever you use). For me, it’s Ghidra. Then, find the address of LastPlayer, which gives you access to the global CPlayer class (LastPlayer is basically a pointer to it LastPlayer = this). From there, you locate the elements you need, like Scripting and Device, using their offsets. You can find these in Ghidra by checking functions registered via addGlobalFunction. And in the end, you just add your own JS functions to the list. The key is having the source code to grab Irrlicht that comes with it. Just add the Irrlicht folder to your DLL project in Visual Studio and include the headers and sources. Honestly, it’s not complicated at all. |
||||
|
The problem with access was that I was using the wrong version of Irrlicht — I had version 1.5 (15.12.2008) without realizing that the source code actually uses a modified version specifically for CopperCube, marked as version 1.5 (...12.2008). Once I added that exact version, everything worked, and accessing Device was no longer an issue. Technically, you don’t even need to depend on the Irrlicht library at all. You could just grab the addresses and use the correct vtables for the methods you need in different classes, since they’re all present in the executable. The catch is that rewriting everything this way is super time-consuming if you’re pulling data from a decompiler. |
||||
|
This is a very cool addon, can you please explain what kind of custom code can be implemented? I mean what kind of functionality can actually be added to the game apart from gamepad compatibility? |
||||
|
At the moment I’ve put together this little set of functions for myself: ccbUpdateGamepadState ccbDrawLine ccbDrawText ccbMakeColor ccbGetSceneNodeParent ccbGetSceneNodeFromRay ccbPointOfWorldWithLine ccbGetNormalFromRay ccbSetSceneNodeCollision ccbGetOpenSaveCommonDialog ccbShowMessageBox ccbDirectoryExists ccbCreateDirectory ccbDeleteDirectory ccbWriteBinaryFileContent ccbReadBinaryFileContent ccbSetWindowSize ccbSetRenderSize Since I’m working with version 6.3 (the last 32-bit build of the engine), I also ported some of the newer functionality from 6.6, tweaking a few functions along the way. For gamepad support, I’m using an XInput array where the index corresponds to the selected gamepad (1 out of 4, since XInput supports up to 4). That way you can grab values like XInput[0].LX and get the left stick value in the -1 to 1 range. There’s also a Resolutions array with all available screen sizes, so for example you can get the smallest resolution with Resolutions[0].width and Resolutions[0].height. |
||||
|
Forgetting the new funtionality that could be added... In theory, is it possible to create a dll for every single coppercube/irrlicht command? If so, does that mean it's also possible to reshell coppercube with a new GUI that just injects required dll's into the game, without needing the engine soucecode? |
||||
|
That's pretty cool, @wing But is it impossible to make supply these functionality alongside the file so that when we download your file from itch and run it, the engine will automatically have them? |
||||
|
VP, not sure I fully got your question, but if I did, then no — without the source code you can’t make libraries to build your own engine on top of. If you meant whether it’s possible to change CopperCube’s UI, then not really… but you can extend the editor’s JS functionality, which lets you create various plugins for the engine. Des, your question’s also a bit unclear, but if I understood it right, then it’s more “impossible” than “possible.” The engine itself stores the executable template inside, and when you compile, it just builds an EXE by adding your scenes into that template. That’s basically how the custom binary feature in version 6.7 works — it swaps out the binary code of the executable that’s hardcoded into the engine. In theory, you could create a patcher that modifies the engine’s data, but honestly injecting DLLs into the engine is already borderline against the license agreement, and full-on patching/modifying the engine’s own code would definitely be a violation. That said, linking an external library to your game is totally fine, since the compiled game itself is mostly your own product. |
||||
|
Ok, thanks for the answer |
||||
|
Thanks, got it. |
||||
|
Interesting conversation, I understand many people want to change many things in coppercube editor, but unfortunaly at I know is not possible yet, I think the best solution if someone need or want one specific resource or tool make like just in case, robo, hadoken or sven and create one plugin, or the most extreme solution use or create another game engine. There are many things interesting one person that understant of programing languade can do with these resource of export one game with one custom code, just in case and robo bring a lot of things that help a lot, maybe give one look in the code of them you find what you need In my opinion coppercube need a lot of things to became better, support to specular and emisive map like the normal map suport and with posible occlusion map and enviroment map suport too, the suport for normal map and these other map for animated 3d objects. hemisferic light type, posibility for create flashlight using spot light from coppercube. Better physics support like sven plattaform extension. The possibility to create and move behavior in groups to organize behaviors except the scene behavior before the first render, create and move action in groups with the user want. The guest actions to control light, vertex light and dynamic light during one game. The resize action windows like just in case extension. One action of commentaries to write information to you now what you did in you code. One action to control proprieties like font, size, color and others things from one 2d overlay. One action like change proprieties from just in case. The possibility to change the scenes order. One action when one node colide if another node. More listed special variables from the in built extensions to change during one game using the action set variable. In the scene the global nodes and scene nodes, in global nodes with will have all objects that will appear in list nodes to use and apply in one scene, in scene nodes we will see only the nodes that exist in one scene or level. The posibility to select and des select one triangle from one static mesh in edit tools. the possibility of join more than two static mesh in one static mesh in edit tools. The possibility of more low blur values, because the coppercube blur shader is too much strong in minimum value allowed in coppercube post processing. better color support in coppercube like blender 2.79 One feature that probably is distant yet to be made is the exportation for linux using format appimage, and native editor for linux I dont thing is necessary yet change the render system, in this case change the directx 9 and opengl 2.1 I dont thing is necessary yet change the light system, would be more interesting in the moment the better texture and material support, and new in built shaders like motion blur, chromatic aberration, sharp, color grading, brightness, contrast, gama and saturation control in coppercube post processing thanks the attention |
||||
|
Sorry I wrote wrong somethings, the right text The actions made from guest to control light, vertex light and dynamic light during one game. One action of commentaries to write information to you know what you did in you code. In the scene the global nodes and scene nodes, in global nodes with will have all objects that will appear in list nodes to use and apply in any or all scenes of one project, in scene nodes we will see only the nodes that exist in one scene or level. Thanks the attention |
||||
|
|