• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Is there theoretically a way to change a game maker defined variable externally through buffers?

Just thinking about some possibilities here to make up for some of GMs pitfalls.

I'm not really an expert on the topic of buffers either but I was looking through the manual and just reading up on buffers in general, probably not the first one to ask this
and probably wont be the last, but I was thinking about exporting a game maker variable to an external source somehow maybe something like powershell and change the variable.

Would this be possible and are there any practical examples?
 
You want to write to and read from a file?
No more like write some sort of external tool which communicates with GM's window and able to modify variables through that instead of GM.

I know there are things like DLLs but just trying to think of easier alternatives before trying to wrap entire libraries, for example PowerShell.
 

Nidoking

Member
Sounds like you want to write malware, only the payload is specifically manipulating your own game. I wouldn't recommend that. You might want to read up on "inter-process communication" and operating system features that let programs talk to each other in controlled, sensible ways that aren't going to get you on every antivirus naughty list.
 
Sounds like you want to write malware, only the payload is specifically manipulating your own game. I wouldn't recommend that. You might want to read up on "inter-process communication" and operating system features that let programs talk to each other in controlled, sensible ways that aren't going to get you on every antivirus naughty list.
With all due respect, there's a 1000 ways to make malware hell there are even execute_shell dlls on the market...
But trying to pass Variables back into GM I don't really see how...

Anyways ....

There are plenty of examples as to WHY you might want to do this. Here's' a pretty elementary example.

Gamemaker still after all these years doesn't have a "Select A Directory" Option to get a directory for users who are making lets say level editors for their game to read and write to.
You can accomplish this with Powershell scripts by passing the Window_handle and converting that handle into a decimal number, you can take
advantage of C# user32.dll features and Pass back the directory as a string, now if you already have a winAPI wrapper then its as simple as creating an EditBox handle stuffing the String into that editbox have GM read the directory upon window close. Done... But for people who don't and don't want to learn hours of C++ to write a whole wrapper library Powershell is their best aside from the fact that you only really need to edit one file for a specific feature.


but we can do it a step further... why not write a Loopable Powershell script that gets WM Messages from WinAPI to keep track of external tools you build?

Lets say you want to build a new window that has a treeView with nodes and you want to interact with it directly from GM

These are some of the examples. Learn to think broadly my friend...
GM as much as it has evolved still has many qualities of life that are still missing from making it a true beast and hell since GM 6 the only option for feature that aren't included in GM is to do it externally
 
Last edited:

Roldy

Member
to think of easier alternatives
Again.... you want to read and write to files? That is the simplest and most straightforward way to do IPC.

If you wanted to get fancy and go beyond simple files you could think about a fifo pipe. Unfortunately Windows doesn't have the best user support for pipes but since you seem to like PowerShell you can probably figure it out. If you are going to be working an a more posix compliant system than Windows then go for pipes or mmaps.

But you could probably get up and running quickly be simply using flat files. KISS.
 

chamaeleon

Member
A variable is memory reserved for a given program. Accessing and changing memory of another process would be a massive security fail. What operating systems can provide is shared memory facilities. Posix shm_open and Windows CreateFileMapping would be candidates for that.
 

Juju

Member
In short, no, it is not possible to directly manipulate GM variables. You can, however, write a GML interface that communicates with a DLL (get/set) and that is typically the preferred way to do things, though this has some obvious shortcomings.

You can also achieve similar things by using a buffer, as you say, and it is possible to directly manipulate buffers on the GML side as you can pass a pointer to a buffer to a DLL (buffer_get_address(), and use the string datatype when registering the DLL function). You would still need to write an interface on the GML side to read that buffer, however, so this may end up being only a marginal gain.
 

Damderiam

Member
Remove this please. I don't want anyone to think that someone proposing to write literal malware is a friend of mine.
I'd be interested to hear what your definition of "malware" is, because based on this thread it seems to be "any program that interacts with any other program".
 
I'd be interested to hear what your definition of "malware" is, because based on this thread it seems to be "any program that interacts with any other program".
I'd be interested to hear what YOUR definition of malware is, editing memory values is literally a type of malware, see any game hacking video. This is also what cheat engine does.
 

Damderiam

Member
I'd be interested to hear what YOUR definition of malware is, editing memory values is literally a type of malware, see any game hacking video. This is also what cheat engine does.
That's kind of like saying all water is ice because all ice is water. Malware is defined by intended effect, not by the method by which that effect is achieved.
 

Nidoking

Member
There are lots of ways for programs to interact with other programs that aren't "write directly into memory space that wasn't allocated to you". Several of them have been mentioned here. All of them share a common feature: Both programs engage with the transport mechanism directly. Whether that's using the operating system's shared memory functionality, a communication DLL, files, the registry, signals, whatever, the program that will receive the data opens the listening protocol explicitly. If you don't know the difference, don't make computer programs. I know I've gotten in trouble on the forum for telling people to stop programming, but if you really don't understand why injecting values into another program's space is malware, don't write any program at all.
 

Roldy

Member
While there are plenty of legitimate reasons to want to poke other software's protected memory space it simply comes down to this being about the most difficult way to implement and manage IPC. All the ways presented to OP are way easier to implement and manage than what OP wants to do.

Which leads one to believe that OP does not control the source of the software they want to poke.

Again there is plenty of legitimate reasons for wanting to manipulate other peoples' software runtime/memory ( Dwarftherapist saved my life), but I don't think this is the forum to discuss it.

If OP has source to the GM developed program then dlls, files, or shared memory services are the answer.
 

Mert

Member
No more like write some sort of external tool which communicates with GM's window and able to modify variables through that instead of GM.

I know there are things like DLLs but just trying to think of easier alternatives before trying to wrap entire libraries, for example PowerShell.
If I remember correctly, @YellowAfterlife has a working extension which allows you to change/inject GML codes in real-time right from the IDE to the game window(You'll be able to not only modify variables, but also the functions, sprites etc.) Maybe you're looking for something like this.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
If you want an easier experience with writing native extensions for GameMaker, I have a number of things published on GitHub,

Specifically:
  • GmxGen automates the process of matching exposed extension functions to what's in your code. For big projects, this saves perhaps the most time.
  • GmlCppExtFuncs auto-generates wrapper functions, allowing for more types (like int64s, tuples, structs, vectors) to be exchanged between C++ and GML easily.
  • GMSDLL is a starter project I use for extensions. It has both of above set up as post-build and pre-build steps respectively.
You can also see the various open-source GM extensions I made as reference

Back to the original question, you can access globals with variable_global_* functions and you can structure your extension accordingly - e.g. for my Lua extension, when the extension needs something from GM, the Lua state stores that data and yields. The extension then returns control to GML with a status code, GML gets what it was asked to, and calls the extension again to resume Lua execution with acquired value.

Depending on version, there may be obscure hacks to do more (e.g. this extension uses undocumented behaviour with ptr(struct_val) to figure out where built-in functions are), but these can come and go at any moment.
If I remember correctly, @YellowAfterlife has a working extension which allows you to change/inject GML codes in real-time right from the IDE to the game window(You'll be able to not only modify variables, but also the functions, sprites etc.) Maybe you're looking for something like this.
Rather than injecting bytecode (which, although fun, would be hard to do across supported platforms - especially consoles and HTML5) GMLive spots a GML compiler (which pumps out array and struct based "instructions") and an interpreter for those instructions. I have a small example of compiler-interpreter parts on GitHub.
 
At everyone who gave insightful and reasonable responses instead of assuming I'm trying to write some form of malware through GM.
Thank you for the help.

If you want an easier experience with writing native extensions for GameMaker, I have a number of things published on GitHub,

Specifically:
  • GmxGen automates the process of matching exposed extension functions to what's in your code. For big projects, this saves perhaps the most time.
  • GmlCppExtFuncs auto-generates wrapper functions, allowing for more types (like int64s, tuples, structs, vectors) to be exchanged between C++ and GML easily.
  • GMSDLL is a starter project I use for extensions. It has both of above set up as post-build and pre-build steps respectively.
You can also see the various open-source GM extensions I made as reference

Back to the original question, you can access globals with variable_global_* functions and you can structure your extension accordingly - e.g. for my Lua extension, when the extension needs something from GM, the Lua state stores that data and yields. The extension then returns control to GML with a status code, GML gets what it was asked to, and calls the extension again to resume Lua execution with acquired value.

Depending on version, there may be obscure hacks to do more (e.g. this extension uses undocumented behaviour with ptr(struct_val) to figure out where built-in functions are), but these can come and go at any moment.

Rather than injecting bytecode (which, although fun, would be hard to do across supported platforms - especially consoles and HTML5) GMLive spots a GML compiler (which pumps out array and struct based "instructions") and an interpreter for those instructions. I have a small example of compiler-interpreter parts on GitHub.
This is quite a wealth of knowledge, thank you. Yeah I'm trying to see if there's a way to be able to get window messages from another window and send it back to GM.

I'm not quite skilled in C++ and have okay C# and Powershell.

I have a winAPI extension that was pretty old that seems to be no longer worked on but there's no way to get WM messages for specific Controls .... Its a great Api but alas it's super incomplete unable to do more of the advance stuff like tree node dragging, allowing decimal values for pretty much anything in editboxes, dragbar etc....

I was thinking of making some sort of event listener by pairing up with an external window generated by GM in a listbox and having GM read from it every step and execute each 1 FIFO via json parse and grabbing the command

I thought it'd be a great idea to create the UI through Electron.js and hook it to GM's window, (iirc that's kinda how you have the window resize fix?)

and have that do all the work since doing javascript and using electron is not as painful and much more customizable, but again it goes back to calling back to GM and actually setting the variables and stuff.

For example doing a drag in a treenode should update the position of an objects struct array in GM etc. Or updating an editbox should actually change text or the objects x and y position and able to assign ranges in an editbox to scroll the value up or down and all the goodies that comes associated with JS and HTML.

Granted GM is easier to create dynamic resources and do custom actions etc in HTML5 but I wanted something mostly for windows hence going the electron route since it boast of having great cross-platform compatibility, I know electron is technically just a browser wrapped but it has quite a lot of win32 uses, at least more than GM will probably ever have.

I'll Have a quick look at some of the examples and see if I can come up with a decent solution instead of rewrapping win32 probably
 
Last edited:
Top