Custom Game.exe Source Code

Don't do it with its ID :b
  1. struct RGSSBMINFO{
  2.     DWORD unk1;
  3.     DWORD unk2;
  4.     BITMAPINFOHEADER *infoheader;
  5.     LPBYTE firstRow; //RGBQUAD *firstRow;
  6.     LPBYTE lastRow;
  7. };
  8.  
  9. struct BITMAPSTRUCT {
  10.     DWORD unk1;
  11.     DWORD unk2;
  12.     RGSSBMINFO *bminfo;
  13. };
  14.  
  15. struct RGSSBITMAP {
  16.     struct RBasic basic;
  17.     void (*dmark)(void*);
  18.     void (*dfree)(void*);
  19.     BITMAPSTRUCT *bm;
  20. };
  21. #define RBITMAP(obj)   (R_CAST(RGSSBITMAP)(obj))
  22.  
  23. VALUE Function_that_receive_a_bitmap(VALUE self,VALUE object)
  24. {
  25.   rb_check_type(object,T_DATA); //Checking if it's a DATA object. (Bitmap Are Data Object)
  26.   struct RGSSBITMAP* bitmap=RBITMAP(object); //Not sure for "RGSSBITMAP*"
  27.   if(bitmap->basic.klass != RGSSConst(kBitmap)) //RGSSConst(kbitmap) is the bitmap class, you should define it somewhere.
  28.   {
  29.     rb_raise(RGSSConst(eArgError),"Argument is not a Bitmap.");
  30.     return 0;
  31.   }
  32.   //Do your stuff here
  33.  
  34.   return 2;//true
  35. }
Expand to see the code.

Bitmaps should probably have a different structure in RGSS2, checks it by reading the memory of a Bitmap object ^^'
You can also use Ruby macro Data_Get_Struct for getting DATA from Ruby objects (copied from ruby.h from include folder in source code of ruby interpreter):

  1.  
  2. struct RBasic {
  3.     VALUE flags;
  4.     const VALUE klass;
  5. }
  6.  
  7. struct RData {
  8.     struct RBasic basic;
  9.     void (*dmark)(void*);
  10.     void (*dfree)(void*);
  11.     void *data;
  12. };
  13.  
  14. #define R_CAST(st)   (struct st*)
  15. #define RDATA(obj)   (R_CAST(RData)(obj))
  16. #define DATA_PTR(dta) (RDATA(dta)->data)
  17. #define Check_Type(v,t) rb_check_type((VALUE)(v),(t))
  18.  
  19. #define Data_Get_Struct(obj,type,sval)
  20.     Check_Type((obj), T_DATA); \
  21.     (sval) = (type*)DATA_PTR(obj);\
  22. } while (0)
  23.  
Expand to see the code.


Basically getting the data from ruby variables would amount up to:
  1.  
  2. structure_type *destination_var;
  3. Data_Get_Struct(ruby_variable, structure_type, destination_var);
  4.  
  5. // Use destination_var for what you need. If there is no DATA inside ruby variable, ruby error will be raised.
  6.  
Expand to see the code.


Data types are basically memory pointers to C structures (or C++ objects) stored inside Ruby variable, this way you can make Ruby class wrappers of C structures and not worry about where they are referenced. This one is really vaguely explained inside ruby documentation (especially stuff when making your own Native API Ruby classes. I had to find a lot about it by hand).
Nuri Yuri wrote:
Don't do it with its ID :b
  1. struct RGSSBMINFO{
  2.     DWORD unk1;
  3.     DWORD unk2;
  4.     BITMAPINFOHEADER *infoheader;
  5.     LPBYTE firstRow; //RGBQUAD *firstRow;
  6.     LPBYTE lastRow;
  7. };
  8.  
  9. struct BITMAPSTRUCT {
  10.     DWORD unk1;
  11.     DWORD unk2;
  12.     RGSSBMINFO *bminfo;
  13. };
  14.  
  15. struct RGSSBITMAP {
  16.     struct RBasic basic;
  17.     void (*dmark)(void*);
  18.     void (*dfree)(void*);
  19.     BITMAPSTRUCT *bm;
  20. };
  21. #define RBITMAP(obj)   (R_CAST(RGSSBITMAP)(obj))
  22.  
  23. VALUE Function_that_receive_a_bitmap(VALUE self,VALUE object)
  24. {
  25.   rb_check_type(object,T_DATA); //Checking if it's a DATA object. (Bitmap Are Data Object)
  26.   struct RGSSBITMAP* bitmap=RBITMAP(object); //Not sure for "RGSSBITMAP*"
  27.   if(bitmap->basic.klass != RGSSConst(kBitmap)) //RGSSConst(kbitmap) is the bitmap class, you should define it somewhere.
  28.   {
  29.     rb_raise(RGSSConst(eArgError),"Argument is not a Bitmap.");
  30.     return 0;
  31.   }
  32.   //Do your stuff here
  33.  
  34.   return 2;//true
  35. }
Expand to see the code.

Bitmaps should probably have a different structure in RGSS2, checks it by reading the memory of a Bitmap object ^^'


I tried without ID, which nearly works, but the struct looks totally misaligned so I suppose that the struct format has changed between versions
I'm bumping this with some news.

In a continuation with my bitmap experiments in this exe, I made a union to look through the bitmap class to try and find something related to my input bitmap.

I gave the function the title screen background bitmap (544 x 416 in resolution) and made a union that had 16 32bit integers against 16 pointers to the same union type, I search around a bit for the resolution of the image and found this:
Image

So I'm going to write an RGSS3 bitmap struct mapping now

EDIT: Looks like this isn't a consistent value, changes every now and then to large numbers, so it must be pointing to some other memory location, oh well.
Hmm... [4], [6] and [14] look like pointer values, [12] and [13] are 99% bitmap width and height. [2] might be a color... kinda looks like one. :)
I believe it's a pointer to something else as it changes to weird values every other launch of the game, so it could be anything unfortunately.
RGSS3 bitmaps are the same as RGSS1 bitmaps :
Image
I did :
  1. @a=Bitmap.new(8,8)
  2. @a.set_pixel(1,1,Color.new(255,0,255,128))
  3. raise "#{(@a.object_id*2).to_s(16)}"
Expand to see the code.
The RGSS1 bitmap functions really don't work for me, the bitmap header is always an invalid pointer and the adjacent pointers don't match as the header either
Oh.
How do you called it ? Can you send me the code ?
Aha I got it working, I didn't realise that the first argument for Global functions is the calling module, what I was doing was shifting around the pointers to find the bitmap, I added param 1 to the function and now it all works.

Guess that teaches me to learn Ruby before trying to dick around with it, sorry for being sucky, I'll package up and release what I've done.
:b
I got a similar problem when I started to extend ruby :3
This is cool:
Image

So now I can look into my plan of having OpenGL target given RPG Maker 'Pictures' as a frame-buffer for rendering.
Awesomeness! I can't wait to see what comes out of this!
I should make a new thread about the OpenGL stuff as it's a separate project to the custom Game.exe source code.

EDIT: Actually, where would I make a thread about this? Can't find a section that would suit it...

Is there scripts in development?

Anyway, for now:
battleworldrpg.net/hbgames/GLtest2.zip

Load up the game (Uses a custom Game.exe, so warning about that) and talk to the girl, she'll show a picture that will quickly be replaced with an OpenGL frame buffer

That is a very basic OpenGL test, what it does is replace the update for any game picture with the draw call that is inside the custom Game.exe (Or xiGame.exe, I left that one in there :U)

It's VERY rough and basic, at the moment it just draws that triangle with the 3 vertices set to colours that have an alpha of 0.5f.

To repeat; the plan is make it so you can target any game picture as if it's a 3D buffer, draw your crap to it and then display it using picture as you want, from this we can start looking into post-processing shaders (FXAA in RPG Maker, haha) and cool screen-space effects like zoom in with a bilinear filter (At the moment I have it set to nearest neighbour filtering).
Quote:
EDIT: Actually, where would I make a thread about this? Can't find a section that would suit it...

I'm not too sure... so I'll leave it up to you to decide if you want it in scripts, programming, projects or completed games.

I mean, we have a few things (Dargor's FF for example) that could fit together, but not enough to fill a board I don't think.

It's "extending RPG Maker" I guess.
I'll make a thread in Projects in Development then, I plan to make a sort of API for doing post-processing rather than a complete scripting system.


Nice to have got everything working, though
Image
The link is down, could you update it ? Also, would there be a way to have a custom Game.exe for RPG Maker XP ? Would this one work if I adapt it ?

Thanks for your work !
The original website is gone now.

Writing custom Game.exe's isn't as useful as one would think, it may be better to go the way of making custom DLL's.

Sorry!

In the future I may make a cleaner version of this tutorial
Actually I would like to edit the icon, get rid of Game.ini and add a launcher before the actual game, is that possible ?
natinusala wrote:
Actually I would like to edit the icon, get rid of Game.ini and add a launcher before the actual game, is that possible ?

You could achieve this by having another launcher application that launches the normal game.exe when you click "play" or something.

You could even parse command line arguments to Game.exe from the launcher so you could prevent a player booting the game from Game.exe directly or you could parse in arguments depending on the settings given in the custom launcher.
Sounds interesting, how could I get the parameters from RGSS ?
If you are familiar with the Win32 API and its RGSS class you can get command line arguments with this;
  1. getCommandLine_f = Win32API.new( "Kernel32", "GetCommandLine", "", "P" )
  2. startupString = getCommandLine_f.call
Expand to see the code.

That will return the startup string, you'll need to do split the startupString into the components to get the arguments.

Once you split it up into multiple strings, you just need to match your given argument to one of those strings and that's how you know if it exists.

It should be in order too, so you can test for a key and presume the next string is the value for that key.
Okay, thanks :)
Can you make a new link? plis.
terabin wrote:
Can you make a new link? plis.

I will make a new download when I improve this project. At the moment I think too many people are using my Game.exe source code without enough programming knowledge to know what to do with it, so I'd rather re-write it so it is more friendly for people to use and remove the current version in the meantime.

Like I said to others before, it is very likely that you are able to get the behaviour you want without having to create your own binary.

On that note, I am going to lock this thread.


If you want a feature and you don't know if it needs a script or an event please make a thread in RPG Maker Support viewforum.php?f=247 and we can help you there.
If it does seem like a custom Game.exe is the solution to a need, then someone may make one for you based on what you need.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=77867