0

How does a Program that is already compiled create standalone .exe files without an apparent compiler? Example game making software like GameMaker that lets you create a game, add all the resources, images, scripts etc, and then lets you compile it into an exe file?

One of my theories is that there is already an .exe which is actually a game player and Gamemaker simply copies that exe and then renames it to the game name you've given, and your scripts are converted into opcodes and saved in a separate file, then this renamed .exe accesses the file and executes the opcodes like a virtual machine to play your game.

Another theory would be that the scripts are converted to c++ code by the gamemaker, which the gamemaker then calls the c++ compiler to automatically compile the code into an executable, because I know I can compile some c++ code using windows command line meaning that there is a c++ compiler already included hidden somewhere in windows.

  • Read [The Dragon Book](https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools) & [Operating Systems: Three Easy Pieces](http://pages.cs.wisc.edu/~remzi/OSTEP/). See also [this](https://softwareengineering.stackexchange.com/a/257873/40065) – Basile Starynkevitch Aug 31 '18 at 17:11
  • In the same way that new programs are created from existing libraries; they are *linked together.* – Robert Harvey Aug 31 '18 at 17:18
  • Robert, would you consider narrowing the scope of the question to asking how GameMaker does it? In my view that would be sufficiently narrow and, by happy coincidence, would fit quite neatly with your suggestions (it actually uses both the first form and a variant of the second form). – Alex Aug 31 '18 at 17:24
  • 1
    How do you know my name? Anyway ok, to be precise, tell me how Gamemaker does it. – Robert Tattorn Aug 31 '18 at 17:44
  • see [Why we're not customer support for \[your favorite company\]](https://meta.stackoverflow.com/q/255745/839601) – gnat Aug 31 '18 at 18:16
  • https://help.yoyogames.com/hc/en-us/articles/227860547-Required-SDKs – Ewan Aug 31 '18 at 18:48
  • @RobertTattorn: You don't see your name on your comments and the question you posted? – Robert Harvey Aug 31 '18 at 21:47
  • Ok now I see it. – Robert Tattorn Aug 31 '18 at 21:54

2 Answers2

2

Generally, you can append data to the end of an executable, and the executable will happily run as though nothing happened.

You can utilize this by having your executable read data from the end backwards, and take action accordingly. This is how self extracting zip files work.

Gamemaker most likely does not build an entire exe from scratch, but instead ships with a runtime and interpreter, which doesn't ever change. On load, the interpreter reads your scripts and resources from the end of the file, then executes them. This is how VB6 applications worked when made into .exes.

It's quite possible that you can open your exe in a program like 7z and see all your files packaged in there.

whatsisname
  • 27,463
  • 14
  • 73
  • 93
0

Well, how does your compiler do it?

After all, a compiler is an already compiled program that generates executibles. It takes some input - source code, game maker data, some diagram, whatever - and spits out some alternative form of that input. It can be an exe, but doesn’t need to be, the concepts are the same.

I am not familiar with gamemaker internals, but if I had to guess it likely behaves like your first theory. It has some well known scaffolding code that starts up, loads the game data (likely embedded in the exe) into some internal representation, and then runs it.

The gamemaker app is just a UI to define that internal representation and enough knowledge to write it to disk alongside executable bits that know how to process it.

Telastyn
  • 108,850
  • 29
  • 239
  • 365