Jump to content


Photo

Gmapi V0.6.2 [updated: 26 Feb 2010]


  • Please log in to reply
338 replies to this topic

#1 Snake_PL

Snake_PL

    GMC Member

  • New Member
  • 57 posts

Posted 22 April 2009 - 02:36 PM

Posted Image

About...


GMAPI is a library for Game Maker DLL developers, that gives the possibility of accessing the game's resources right from the DLL! What it currently features:

  • Ability to use the GML functions within your DLL.
  • Possibility to modify or even register a new GML functions for the game (increases external calling efficiency)
  • Direct access to the game resources, such as:
  • Sprite, background and font bitmaps
  • Sound files
  • Local and global variables/arrays
  • Built-in variables/properties (e.g room_speed, fps)
  • Internal game structures (e.g. the one that holds GM instance's data)
  • Game's Direct3D interfaces (IDirect3D8, IDirect3DDevice8, IDirect3DTexture8)
In the current version you have a possibility to access sprites, backgrounds, surfaces, sounds, scripts, particles, fonts and some other data, such as e.g. game's Direct3D interfaces, window handles, GML functions, GM version and more. Soon I'll try to give you possibility to access other runner's data as well... I'm also thinking about adding new features like adding a sprite to game from bitmap loaded in memory. Well, you can give suggestions what could be added to the library (BTW. something important/useful related to DirectX will be welcomed - I don't know much about that library ;p). Unfortunatelly, because of lack of time i didn't wrote a documentation... there are only some examples & comments in a header file... here i'll explain most important things.
Library is released on LGPL license, so everyone can take a look at the source and check out how it is made, or modify... :(
When project will be in more advanced stage (and there will be time for this ofc) i'll make the library compatible with MinGW compiler ;o

Using the library


Installation

All you have to do is extract the archive to chosen directory and specify the paths to "include" & "lib" directories in IDE. Run Visual C++, select from "Tools" menu "Options..." item, next go to "Projects and Solutions" >> "VC++ Directories" node, now select "Include files" from the "Show directories for" combobox and add the path to "include" directory from GMAPI, then select "Library files" from the combobox and add the path to "lib" directory. Done.

Initialization

Before you'll begin to work with the library you must include gmapi.h header to one of the source files in your project. If you don't have DirectX SDK installed define GMAPI_NO_D3D before including gmapi.h (D3D interfaces will be defined as void), thus this will look like:

#define GMAPI_NO_D3D
#include <gmapi.h>
Now you must add to the library dependencies proper static library - all depends on which runtime library you choose in your project:

gmapi-mt.lib - Multithreaded
gmapi-mt-dll.lib - Multithreaded DLL
gmapi-mt-d.lib - Multithreaded debug
gmapi-mt-d-dll.lib - Multithreaded debug DLL

Next, you must create main library object, that is CGMAPI class. That class is a singleton, so only one instance can be created at runtime in your library. To create an instance of this class use CGMAPI::Create static method, which takes as parameter a pointer to "unsigned long" variable type - it'll be used to return the result of initialization (possible values are: GMAPI_INITIALIZATION_SUCCESS - if initialization succeeded; GMAPI_INITIALIZATION_FAILED - when initialization fails; GMAPI_ALREADY_INITIALIZED - when an instance of CGMAPI class already exists). The method returns pointer to newly created class object, which you should store in a variable. I recommend to do this in DLL's entrypoint, that is DllMain function, for example:
gm::CGMAPI* gmapi;

BOOL WINAPI DllMain( HINSTANCE aModuleHandle, int aReason, int aReserved ) {
  switch ( aReason ) {
    case DLL_PROCESS_ATTACH: {
      // Initialization
      unsigned long result = 0;
      gmapi = gm::CGMAPI::Create( &result );

      // Check the result
      if ( result != gm::GMAPI_INITIALIZATION_SUCCESS ) {
        MessageBox( 0, "Unable to initialize GMAPI.", 0, MB_SYSTEMMODAL | MB_ICONERROR );
        return FALSE;
      }

      break;
    }

    case DLL_PROCESS_DETACH:
      // Release from memory & deinitialize GMAPI
      gmapi->Destroy();
      break;
  }

  return TRUE;
}
CGMAPI::Destroy() method frees the class instance from memory. BTW, all classes, functions, constants etc. in GMAPI are declared in "gm" namespace. You should not call any GML functions immediatelly after initialization - GMAPI hooks external_call function in runner in order to retrieve pointer to current instance (that is, from which the function is called) which is needed to call all GM functions properly in DLL. So, it is necessary to return to GM after initialization. When class object has been created without any problems you can call the GML functions from within your DLL and, of course, you can use CGMAPI class components.

Calling GM functions

When GMAPI is initialized you can now call GM functions from the DLL. All functions are nicely wrapped in the library so you can call them in a simple way, take a look:

int list;
gm::CGMVariable value;

list = gm::ds_list_create();

gm::ds_list_add( list, "test" );
gm::ds_list_add( list, 12345.12345 );

value = gm::ds_list_find_value( list, 0 ); // store "test" in the variable
value = gm::ds_list_find_value( list, 1 ); // return 12345.12345 to the variable

gm::ds_list_destroy( list );
CGMVariable class object that is defined in this code snippet mimics the GM variable, so it can be set to either string or real value. It must be used to store return values from functions that can return values that type is not known (e.g. ds_list_find_value can return either string or real). Also, you must pass it in parameters in some GM functions for the same reason... besides, that class emulates string type from Delphi - it deals with string allocation, "conversion" from char*, deallocation etc... using runner - char* is not fully compatible with Delphi string ("length" variable, reference counter for the garbage collector) so i had to do something ^^ Oh, one more thing... you should always return the result of GM function that can return string to the CMGVariable class object - it'll take care of deallocation.
All GM functions are available in GMAPI, excluding math functions and those that are operating on strings (and functions such as is_real or is_string). In addition, class has some constructors overloaded and it can be instatiated implicitly by passing a value in parameters that type is a reference to a CGMVariable class (e.g. ds_list_add takes CGMVariable reference type in second parameter, in above code snippet there will be created an temporary instance of class by passing "char*" or "double" to the function). There are also some operator overloading implemented, like "++", "-=" or casting to double/char*, plus "<<" overload for std::ostream :)

Accessing game resources

You can access them by a three ways: with GM functions of course (least efficent, less possibilities), by GM's structures that I've analyzed in runner and with "accessing classes" defined in GMAPI. Using structures is most efficent and equally unsafe, I'll explain how to use them in a documentation that I'll write later. Meanwhile, you can use the classes I mentioned - they're safer and easier to use than using the GM's structures. Why I called them "accessing" (wtf) ? Well, they're operating entirely on runner's memory, what is also reason why using them is somewhat entangled. In CGMAPI class there are some objects of these classes defined: Sprites (ISprites class), Backgrounds (IBackgrounds), Sounds (ISounds), Surfaces (ISurfaces) and Scripts (IScripts). All of these classes shares some methods that can retrieve various data that is relevant to respective GM resource type (for example, GetID() returns an ID of specified resource by given name of this type, GetCount() returns number of resources of this type) and all of them have an array operator ("[]") overloaded that returns reference type to next "accessing classes" - these classes gives you access to resource with ID specified in brackets. Damn, hard to explain... so, for example:

gm::CGMAPI* gmapi;
(...)
// Let's say that we've added an animated sprite named spr_anim
// to the game, now we want to get width of the sprite
int sprAnim, spriteWidth;

// First, we must get the ID
sprAnim = gmapi->Sprites.GetID( "spr_anim" );

// Now we will get the width
spriteWidth = gmapi->Sprites[sprAnim].GetWidth();

// What if our sprite has not been found because we didn't added it
// to the game ? An exception with EGMAPISpriteNotExists class object will be thrown
// (exception class), we will catch it with "try - catch" of course
try {
  spriteWidth = gmapi->Sprites[sprAnim].GetWidth();
}
catch ( gm::EGMAPISpriteNotExist& exc ) {
  exc.ShowError(); // Show message with information about error
}

// Operator [] in ISprites class returns ISprite reference type - that class is
// the only one of these "higher level" that have defined object of next such
// class - ISpriteSubimages (Subimages object), which gives you access to specified
// sprite subimage. Hm, let's say we want to store all of the texture ID (a'la
// sprite_get_texture from GM) in a vector array:
std::vector<int> textures;

for ( int i = 0; i < gmapi->Sprites[sprAnim].Subimages.GetCount(); i++ )
  textures.push_back( gmapi->Sprites[sprAnim].Subimages[i].GetTextureID() );
Well, that's all about accessing game resources.

Notes:

As I mentioned before, I'll write a documentation later. Meanwhile, you have to rely on IntelliSense, comments in GmapiInternal.h header file and on 3 crappy examples I wrote ;p In GMAPI there are also constants from GM. Of course please report all bugs you've found - project is still in testing stage.

Download:


You can find all the versions of GMAPI here: (the newest is 0.6.2)
http://code.google.c.../downloads/list

Examples:

My BBCode engine ( http://forum.gmclan....showtopic=15031 ) rewritten to C++:
src: http://gmclan.org/up...eEngineSrc.html
demo: http://gmclan.org/up...EngineDemo.html

Bitmap viewer:
src: http://gmclan.org/up...pViewerSrc.html
demo: http://gmclan.org/up...ViewerDemo.html

Direct3D interfaces test (hardcoding crap ;)):
src: http://gmclan.org/up...exampleSrc.html
demo: http://gmclan.org/up...xampleDemo.html

Example of accessing GM variables:
src: http://gmclan.org/up...riablesSrc.html
demo: http://gmclan.org/up...iablesDemo.html

GM function adding/replacing example:
src: http://gmclan.org/up...MFunctions.html

Particle & built-in variables accessing test:
src: http://gmclan.org/up...rticleTest.html

Resources:

GMAPI Wiki: http://gmapi.roket-enterprises.com/
GMAPI logos: http://gmclan.org/up...MAPI_logos.html
DirectX 8 SDK: http://www.darwinbot...x81sdk_full.exe

DLLs that uses GMAPI:

Precise 3D Collisions by brett14
RoketGames Game Integration by Hach-Que
G-pathfinding by paul23
GFFI by Clam
GMOgre3D by Houdini
gmPython by Hach-Que
Xenon PlayGate by PsichiX
Advanced console by TheMagicNumber
gmLua by Kofel


Edited by Snake_PL, 29 September 2010 - 04:56 PM.

  • 4

http://sgames.ovh.org/ - my blog (Polish)

Game Maker projects:
- GMAPI - C++ library for DLL developers that directly accesses various game resources
- GMThreads - Library for Game Maker that allows you to execute GML code in a thread
- Game Protector [PL] - Protects games made in GM5/6.1/7.0 from decompiler
- GM Extractor [PL] - Dumps resources embedded in Game Maker project file to a selected directory
Other projects:
- MemExtractor [PL] - Extracts various resources from the process memory
- OllyDataInterpret [PL] - A plugin for OllyDbg 1.10 that shows different interpretations of selected data in a seperate window.


#2 gnysek

gnysek

    GMC Member

  • GMC Member
  • 613 posts
  • Version:GM:Studio

Posted 22 April 2009 - 02:58 PM

Thanks dude, it's awesome!
  • 0

Previously game developer at YoYoGames, Currently PHP developer in DB-Team
Programming and working with: GML/C#/PHP/JS/MySql/CSS/HTML

Follow 
@GameMakerUpdate to get info about latest versions of GM when they are released: https://twitter.com/GameMakerUpdate or visit website.

(it's managed by bot, not by human, remember)


#3 paul23

paul23

    GMC Member

  • Global Moderators
  • 4147 posts
  • Version:GM:Studio

Posted 22 April 2009 - 03:28 PM

Well as I said in pm, maybe inverse the usage of d3d8.h: it's nowadays difficult to get the directx8 develop thing, (you can't get from MSDN anymore) - so you'll always have to add this line:
#define GMAPI_NO_D3D

maybe make it so that d3d8.h is ONLY used if something is defined....
  • 0

#4 Snake_PL

Snake_PL

    GMC Member

  • New Member
  • 57 posts

Posted 22 April 2009 - 03:36 PM

Ok, I'll correct that in next version.
  • 0

http://sgames.ovh.org/ - my blog (Polish)

Game Maker projects:
- GMAPI - C++ library for DLL developers that directly accesses various game resources
- GMThreads - Library for Game Maker that allows you to execute GML code in a thread
- Game Protector [PL] - Protects games made in GM5/6.1/7.0 from decompiler
- GM Extractor [PL] - Dumps resources embedded in Game Maker project file to a selected directory
Other projects:
- MemExtractor [PL] - Extracts various resources from the process memory
- OllyDataInterpret [PL] - A plugin for OllyDbg 1.10 that shows different interpretations of selected data in a seperate window.


#5 ditdingiscool

ditdingiscool

    GMC Member

  • New Member
  • 335 posts

Posted 25 April 2009 - 08:47 AM

hi there, i'm kindoff new to c/c++ so i neaad some help setting this up, especialy what do i have to do EXACTLY when you say this:

Now You must add to the library dependencies proper static library - all depends on which runtime library You choose in Your project:
gmapi-mt.lib - Multithreaded
gmapi-mt-dll.lib - Multithreaded DLL
gmapi-mt-d.lib - Multithreaded debug
gmapi-mt-d-dll.lib - Multithreaded debug DLL

(using dev c++)

thanks already ;)
  • 0

#6 tuntis

tuntis

    GMC Member

  • New Member
  • 1839 posts

Posted 25 April 2009 - 10:58 AM

(using dev c++)

read
  • 0

#7 ditdingiscool

ditdingiscool

    GMC Member

  • New Member
  • 335 posts

Posted 25 April 2009 - 01:42 PM

(using dev c++)

read

that page doesn't give any real argument, it only has one weak argument "it's outdated", but so is windows xp and that sucks less than vista, but ok, whatever, downloading code::blocks

EDIT:ok, that really solved nothing,

Process terminated with status 1 (0 minutes, 4 seconds)
50 errors, 22 warnings


Edited by ditdingiscool, 25 April 2009 - 01:56 PM.

  • 0

#8 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 25 April 2009 - 02:05 PM

Post some of those 50 errors.
Most probably they'll be linker related errors.
Also,(AFAIK) you'll have to convert those .lib files to .a archives for GCC's linker to use.
Use a tool in your bin folder called REIMP to do this.

Also Snake_PL, what do you use to hook d3d functions ?

Edited by freaked, 25 April 2009 - 02:07 PM.

  • 0

#9 tuntis

tuntis

    GMC Member

  • New Member
  • 1839 posts

Posted 25 April 2009 - 02:09 PM

it only has one weak argument "it's outdated", but so is windows xp and that sucks less than vista, but ok, whatever, downloading code::blocks

...Except that XP is not outdated because MS still provides support for it.
  • 0

#10 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 25 April 2009 - 03:22 PM

If nobody is working on it, can you work on a Code::Blocks version? (Tuntis, if you ever tell me to use VC++, I despise Microsoft products)

By the way, Windows XP was unsupported for a while, but they extended the support, probably because many people downgraded from Windows Vista.
  • 1

#11 tuntis

tuntis

    GMC Member

  • New Member
  • 1839 posts

Posted 25 April 2009 - 04:44 PM

(Tuntis, if you ever tell me to use VC++, I despise Microsoft products)

Well, if you intend on using this thing right now, I can tell you that VC++ Express will be the quickest and most pain-free solution...
  • 0

#12 GearGOD

GearGOD

    Deus Verus

  • GMC Member
  • 2153 posts

Posted 25 April 2009 - 05:08 PM

Tuntis, if you ever tell me to use VC++, I despise Microsoft products

You're not using a dev tool because you despise that company that its affiliated with? Even though its arguably the best one around and free? You're so awesome.
  • 1
Engineers are not programmers. Stop thinking that you can save a few bucks by writing code yourself instead of hiring a programmer. Your code sucks.

#13 ditdingiscool

ditdingiscool

    GMC Member

  • New Member
  • 335 posts

Posted 26 April 2009 - 07:36 AM

Tuntis, if you ever tell me to use VC++, I despise Microsoft products

You're not using a dev tool because you despise that company that its affiliated with? Even though its arguably the best one around and free? You're so awesome.

i'm also not a big fan off vc++, and not only because it's from micro$oft, it has 'adobe reader syndrome'(load a document, have lunch, wait another 10 minutes for it to load), and it isn't able to create empty projects on my pc...

ONTOPIC:
||=== vonoroi, default ===|
C:\Documents and Settings\lieuwe\Bureaublad\bende\GMAPI\dll_vonoroi\GmapiCore.h|32|warning: `GMDeallocateString' initialized and declared `extern'|
C:\Documents and Settings\lieuwe\Bureaublad\bende\GMAPI\dll_vonoroi\GmapiCore.h|32|error: variable or field `GMDeallocateString' declared void|
C:\Documents and Settings\lieuwe\Bureaublad\bende\GMAPI\dll_vonoroi\GmapiCore.h|32|error: `gm::core::GMDeallocateString' declared as an `inline' variable|
C:\Documents and Settings\lieuwe\Bureaublad\bende\GMAPI\dll_vonoroi\GmapiCore.h|32|warning: `__stdcall__' attribute only applies to function types|
C:\Documents and Settings\lieuwe\Bureaublad\bende\GMAPI\dll_vonoroi\GmapiCore.h|32|error: `__in' was not declared in this scope|
C:\Documents and Settings\lieuwe\Bureaublad\bende\GMAPI\dll_vonoroi\GmapiCore.h|33|warning: `GMDeallocateResult' initialized and declared `extern'|
C:\Documents and Settings\lieuwe\Bureaublad\bende\GMAPI\dll_vonoroi\GmapiCore.h|33|error: variable or field `GMDeallocateResult' declared void|
C:\Documents and Settings\lieuwe\Bureaublad\bende\GMAPI\dll_vonoroi\GmapiCore.h|33|error: `gm::core::GMDeallocateResult' declared as an `inline' variable|
<snip>
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 22 warnings ===|

  • 0

#14 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 26 April 2009 - 09:22 AM

Honestly, I think you should have made this compatible with the GCC compiler also.

You're not using a dev tool because you despise that company that its affiliated with? Even though its arguably the best one around and free? You're so awesome.


Errr, he's not trying to be awesome, he has just been mis-guided about Microsoft products.

A lot of them are actually pretty good, and VC++ is one of them.
Honestly, if you were to ever download a Microsoft product, I reccomend you try that one.

Download Visual C++ Express

You could have at least been helpful GearGod. :/

EDIT: Honestly, I think GMREC uses linux anyway, and I have no clue why he is really worrying about Game Maker in the first place... I don't think WINE can even run it.

Edited by X-tra Fear, 26 April 2009 - 09:27 AM.

  • 0

#15 tuntis

tuntis

    GMC Member

  • New Member
  • 1839 posts

Posted 26 April 2009 - 10:38 AM

Errr, he's not trying to be awesome

Oh trust me, this guy refuses to use pretty much any Microsoft technology because it's a "giant fag company". Funny how he still uses Windows...
  • 0

#16 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 26 April 2009 - 11:29 AM

Errr, he's not trying to be awesome

Oh trust me, this guy refuses to use pretty much any Microsoft technology because it's a "giant fag company". Funny how he still uses Windows...


Ohhhh, I don't really know him all that well... lol.
  • 0

#17 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 26 April 2009 - 12:11 PM

Lol. GMREC and me even had PM discussion involving C::B's greatness and MSVC's suckiness.
  • 0

#18 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 26 April 2009 - 02:11 PM

Funny how he still uses Windows...

Rarely.

And I did want a GCC version.
  • 1

#19 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 27 April 2009 - 12:09 AM

What is weird is your DLLMain, which is proper to use in that manner but... I found out a while back in my dlls that this is never called for dll's used by GM (7)
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#20 paul23

paul23

    GMC Member

  • Global Moderators
  • 4147 posts
  • Version:GM:Studio

Posted 27 April 2009 - 10:45 PM

What is weird is your DLLMain, which is proper to use in that manner but... I found out a while back in my dlls that this is never called for dll's used by GM (7)

? - Uhm well I found out that they are actually called, DLL_PROCESS_ATTACH, when you 'initialize' your first function.. And DLL_PROCESS_DETTACH when you unload the dll. (Also using GM 7)
  • 0

#21 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 27 April 2009 - 11:15 PM

What is weird is your DLLMain, which is proper to use in that manner but... I found out a while back in my dlls that this is never called for dll's used by GM (7)

? - Uhm well I found out that they are actually called, DLL_PROCESS_ATTACH, when you 'initialize' your first function.. And DLL_PROCESS_DETTACH when you unload the dll. (Also using GM 7)


I'll have to redo my tests. Because that caused me quite a few problems before. I always used that function in all my non GM dlls to initialise/free global things and it just would not be called by GM... But you may be right. I may have done something weird at the time...
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#22 paul23

paul23

    GMC Member

  • Global Moderators
  • 4147 posts
  • Version:GM:Studio

Posted 04 May 2009 - 10:38 PM

Well after using this for several weeks I'm still wondering something: how (and IS) it possible to get the "standard global variables" (room_width/height, views etc)?
  • 0

#23 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 04 May 2009 - 11:46 PM

Well after using this for several weeks I'm still wondering something: how (and IS) it possible to get the "standard global variables" (room_width/height, views etc)?


GM has no functions for those. Which is too bad because we may want to know this information without actually wanting to be in the room


Make a GetGameData script in your game

call val = ScriptExecute("GetGameData", "room_width") in your c++ code


script GetGameData
//GetGameData(dataname)
swicth(argument0)
{
case "room_width": return room_width;
case "room_height": return room_height;
...
}
return 0;

Edited by icuurd12b42, 04 May 2009 - 11:49 PM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#24 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 05 May 2009 - 01:30 AM

Why not just use execute_string?
  • 0

#25 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 05 May 2009 - 01:48 AM

Why not just use execute_string?


I guess that would work if it can return a value... Slower but that would work.

Edited by icuurd12b42, 05 May 2009 - 01:48 AM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#26 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 05 May 2009 - 03:12 AM

Well I figured it was something you'd only call once anyway. Or very rarely at least.
  • 0

#27 paul23

paul23

    GMC Member

  • Global Moderators
  • 4147 posts
  • Version:GM:Studio

Posted 05 May 2009 - 01:58 PM

Well I figured it was something you'd only call once anyway. Or very rarely at least.

Indeed: once you "get" a veriable you would always store it as an internal C++ variable (I always try to minimize the amount of calls back to GM).

Anyways a new error popped up:

ERROR in
action number 1
of Create Event
for object obj_control2:

Error in code at line 1:
return room_width

at position 1: Internal Error: Executing code for nil instance.


I've put the code into the dll_process_attach part.
double d;
		d=gm::execute_string("return room_width");
		gm::show_message(boost::lexical_cast<std::string,double>(d));
(ignore the show_message).


Well putting it into an "explicitelly" called function (ie an "init" function) it does work.. - But that defeats the purpose a little bit. (In that case I could've given the values as "arguments" already).
  • 0

#28 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 05 May 2009 - 07:08 PM

Well I figured it was something you'd only call once anyway. Or very rarely at least.

Indeed: once you "get" a veriable you would always store it as an internal C++ variable (I always try to minimize the amount of calls back to GM).

Anyways a new error popped up:

ERROR in
action number 1
of Create Event
for object obj_control2:

Error in code at line 1:
return room_width

at position 1: Internal Error: Executing code for nil instance.


I've put the code into the dll_process_attach part.
double d;
		d=gm::execute_string("return room_width");
		gm::show_message(boost::lexical_cast<std::string,double>(d));
(ignore the show_message).


Well putting it into an "explicitelly" called function (ie an "init" function) it does work.. - But that defeats the purpose a little bit. (In that case I could've given the values as "arguments" already).


Yeah, you are not allowed to do much in the DLLMain, mainly allocate and free memory and possibly load another dll.

I can't remember why doing stuff in the DLLmain is not recomended. These factor are no longer known by me. Perhapse someone with fresh knowledge can jump in and explain why. All I remember is someone cautioning me 15 years ago.

Edited by icuurd12b42, 06 May 2009 - 08:55 PM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#29 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 06 May 2009 - 09:10 AM

The entry-point function should perform only simple initialization or termination tasks. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order. This can result in a DLL being used before the system has executed its initialization code. Similarly, the entry-point function must not call the FreeLibrary function (or a function that calls FreeLibrary) during process termination, because this can result in a DLL being used after the system has executed its termination code.


Edited by freaked, 06 May 2009 - 09:10 AM.

  • 0

#30 coolhome

coolhome

    GMC Member

  • New Member
  • 101 posts

Posted 08 May 2009 - 03:23 AM

I get a compiler error when I use v.3.

"Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR' GmapiInternal.h 378"
  • 0

#31 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 08 May 2009 - 04:04 AM

I don't think the version I wrote has any MessageBox calls (and I don't remember the original having any, either). Regardless, go find the call to MessageBox and put an L in front of any string literals you see in its arguments.

I.e. "Hello world!" becomes L"Hello world!".

Hell, just Google "MessageBoxW" and you'll get a bunch of different solutions.
  • 0

#32 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 08 May 2009 - 09:09 AM

Or you can do the following -
#ifdef MessageBox
   #undef MessageBox
   #define MessageBox MessageBoxA
#endif
After including windows.h

Edited by freaked, 08 May 2009 - 09:10 AM.

  • 0

#33 Clam

Clam

    GMC Member

  • New Member
  • 55 posts

Posted 10 May 2009 - 02:11 AM

I wouldn't be surprised if stuff like room_speed was in a hashtable/map/list somewhere, Looking at the code in the runner that handles the display of variables in debug mode would probably be a good place to find out.
  • 0

#34 halo shg

halo shg

    Programmer

  • GMC Member
  • 600 posts
  • Version:GM:Studio

Posted 10 May 2009 - 06:02 PM

Does this mean that someone can build a DLL with the same functions as the one currently in my game, replace it with the one in the games directory, and use the function like sprite_save_from_screen and script_get_text to steal my resources?
  • 0

Dev: MacBook Pro Retina Display 15" w/ Win7 (Parallels) running GM Studio: Master and GM8 (GMS: ANDROID JAVA EXTENSIONS ARE HERE!)
Devices: Samsung Galaxy Note II / Samsung Galaxy S III / iPhone 4S / iPad 2 / iPod Touch 5th gen



Politics' is made up of two words, 'poli,' which is Greek for 'many,' and 'tics,' which are blood-sucking insects.


-Gore Vidal


#35 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 10 May 2009 - 06:16 PM

Yes, but people could already do that.
  • 0

#36 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 10 May 2009 - 06:47 PM

Does this mean that someone can build a DLL with the same functions as the one currently in my game, replace it with the one in the games directory, and use the function like sprite_save_from_screen and script_get_text to steal my resources?



Its a standard way to hack/replace a dll and snoop at what goind on...

Anyway print screen can steal your resource very easilly so why go through all the trouble. A screen capture/recorder works well too.
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#37 Snake_PL

Snake_PL

    GMC Member

  • New Member
  • 57 posts

Posted 17 May 2009 - 10:00 AM

Update:

New features:
  • Access to GM's local/global variables and arrays
  • Possibility to change current instance to other (You can now call GM functions with instance other than that one which calls Your DLL function)
  • Possibility to execute Your code with specified group of instances (a'la GM's with)
  • Access to instance properties/builtin variables (x, y, hspeed, path_index, direction etc.)
More detailed changes:
  • From now to use D3D8 with GMAPI You have to define GMAPI_USE_D3D, "GMAPI_NO_D3D" has been removed
  • GMVARIABLE structure: renamed to GMVALUE, added << operator overload with std::ostream, member names changed
  • New GMVARIABLE structure (it turned out that the previous GMVARIABLE structure represents, in fact, GM's value format - that's why i've renamed above-mentioned structure)
  • CGMVariable: New ctor that takes GMVALUE ref in parameter
  • New methods in CGMAPI class: GetSymbolID, GetLocalVariablePtr, GetGlobalVariablePtr, GetInstancePtr, GetCurrentInstancePtr, GetCurrentInstanceID, SetCurrentInstance, EnumInstances & With. (+ other, unimportant :()
  • Small fixes in GMAPICore\main.asm (+ new GMFindSymbolID function)
  • MessageBox calls changed to MessageBoxA (project with UNICODE character set could'nt be compiled)
  • Prefixes of pointer type definitions in GmapiDefs has been changed from "LP" to "P" (e.g. LPGMSPRITE >>> PGMSPRITE)
  • Several small fixes in comments

Download v0.4:
http://gmclan.org/up...PIv0_4_src.html

Example of usage:
src: http://gmclan.org/up...riablesSrc.html
demo: http://gmclan.org/up...iablesDemo.html

Also Snake_PL, what do you use to hook d3d functions ?

The library doesn't hook any of D3D functions to get the pointers - they're just retrieved from where GM holds them in the memory ;p

If nobody is working on it, can you work on a Code::Blocks version?

I'll work later on MinGW version. First i want to release v1.0 of library for VC++ :D

Well after using this for several weeks I'm still wondering something: how (and IS) it possible to get the "standard global variables" (room_width/height, views etc)?

Now i'ts imposible to get that "variables" from GMAPI. This will be available in the next release. For now, You can only use execute_string/script_execute etc. instead.

The "Executing code for nil instance." error appears because You're trying to call GM function immediately after GMAPI initialization - at this point, pointer to the instance from which that DLL function was called is unknown, GMAPI will retrieve it in the next call to DLL. (i mentioned about this in the first post)
  • 0

http://sgames.ovh.org/ - my blog (Polish)

Game Maker projects:
- GMAPI - C++ library for DLL developers that directly accesses various game resources
- GMThreads - Library for Game Maker that allows you to execute GML code in a thread
- Game Protector [PL] - Protects games made in GM5/6.1/7.0 from decompiler
- GM Extractor [PL] - Dumps resources embedded in Game Maker project file to a selected directory
Other projects:
- MemExtractor [PL] - Extracts various resources from the process memory
- OllyDataInterpret [PL] - A plugin for OllyDbg 1.10 that shows different interpretations of selected data in a seperate window.


#38 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 17 May 2009 - 10:48 AM

You shoul paste this update info in your main post.
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#39 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 29 May 2009 - 11:07 PM

---Oops. I guess this doesn't work with MinGW...

Edited by Revel, 30 May 2009 - 12:51 AM.

  • 0

#40 yellowsix

yellowsix

    GMC Member

  • New Member
  • 315 posts

Posted 31 May 2009 - 10:38 PM

Aah awesome. I've been looking quite a while for this Dll. I saw it before, but didn't realize the possibilities back then. I've always wanted to make a game running from a C++ core, using Game Maker as some sort of a layer which handles the graphics. This extension allows me to finally try it out.
Thanks. :medieval:

Edited by yellowsix, 31 May 2009 - 10:39 PM.

  • 0
"Go thy way, eat thy bread with joy, and drink thy wine with a merry heart; for God now accepeth thy works." - Ecclesiastes 9:7

English is not my native language. Please keep this in mind.

"The ruling class has the schools and press under its thumb. This enables it to sway the emotions of the masses." ~Albert Einstein

#41 39ster

39ster

    GMC Member

  • GMC Member
  • 898 posts

Posted 21 June 2009 - 02:02 PM

This is really good. I wanted to use it in my mingw projects so i modified the source code to compile in both mingw and visual C++.

*Must do in this order
-Search for all "__inout" and remove
-Search for all "__in_opt" and remove
-Search for all "__in" and remove
-Search for all "__out" and remove
-Search for all "__deref_inout" and remove
-Search for all "__deref_in" and remove

-Change line 2072 from "PGMINSTANCE& instance = (PGMINSTANCE) *GMAPI_CURRENT_INSTANCE_PTR;" to "PGMINSTANCE& instance = *const_cast<PGMINSTANCE*>(GMAPI_CURRENT_INSTANCE_PTR);"
-Add

#ifdef __GNUC__
#define sprintf_s snprintf
#endif

to "GmapiMacros.h"


Posted Image

EDIT: Unfortunately i can't get the gmapi core ASM file to compile...:/

Edited by 39ster, 21 June 2009 - 02:45 PM.

  • 0

#42 e_barroga

e_barroga

    ES Studios Leader

  • GMC Member
  • 2475 posts

Posted 21 June 2009 - 03:11 PM

This is really good. I wanted to use it in my mingw projects so i modified the source code to compile in both mingw and visual C++.

*Must do in this order
-Search for all "__inout" and remove
-Search for all "__in_opt" and remove
-Search for all "__in" and remove
-Search for all "__out" and remove
-Search for all "__deref_inout" and remove
-Search for all "__deref_in" and remove

-Change line 2072 from "PGMINSTANCE& instance = (PGMINSTANCE) *GMAPI_CURRENT_INSTANCE_PTR;" to "PGMINSTANCE& instance = *const_cast<PGMINSTANCE*>(GMAPI_CURRENT_INSTANCE_PTR);"
-Add

#ifdef __GNUC__
#define sprintf_s snprintf
#endif

to "GmapiMacros.h"


Posted Image

EDIT: Unfortunately i can't get the gmapi core ASM file to compile...:/


Great, MinGW support!
  • 0

rsa_gmc_sig.png

 

logoGIF1.gif EXTENSION. PM TO PURCHASE LICENSE.


#43 39ster

39ster

    GMC Member

  • GMC Member
  • 898 posts

Posted 25 June 2009 - 03:43 AM

I think there is some sort of stack corruption with gm::script_execute() in GM 6.1

Sometimes it crashes, sometimes it works, sometimes it freezes and uses 50% of my CPU. If i change some code in a completely unrelated area it will work, or it will break. All the other functions work (like gm::show_message or something) but gm::script_execute is buggy.
  • 0

#44 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 25 June 2009 - 08:35 PM

OOOPS!!!


void ds_map_exists( const int id, const CGMVariable& key );
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#45 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 04 July 2009 - 01:17 PM

Sorry about the bump. :)

I was wondering if anybody could help me with this problem, it seems that VC++ doesn't know how to handle versions, having Debug compile fine but Release failing with incompatible versions.
fatal error C1047: The object or library file 'C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\gmapi-mt.lib' was created with an older compiler than other objects; rebuild old objects and libraries
I've literally copied settings from some examples, but even the examples didn't work. I have VC++ 2008 Express (SP1).
  • 1

#46 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 04 July 2009 - 11:43 PM

Sorry about the bump. :)

I was wondering if anybody could help me with this problem, it seems that VC++ doesn't know how to handle versions, having Debug compile fine but Release failing with incompatible versions.

fatal error C1047: The object or library file 'C:\Program Files\Microsoft Visual Studio 9.0\VC\lib\gmapi-mt.lib' was created with an older compiler than other objects; rebuild old objects and libraries
I've literally copied settings from some examples, but even the examples didn't work. I have VC++ 2008 Express (SP1).



Open the gmlib project in the gmapicv0.4\src folder and recompile. select the little drop down (option) next the the green play icon. compile once with each option... that will rebuild every output listed in post 1.

Then go to gmapicv0.4\src\lib and copy the new lib files there onto the gmapicv0.4\lib
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#47 Snake_PL

Snake_PL

    GMC Member

  • New Member
  • 57 posts

Posted 19 July 2009 - 09:36 AM

This is really good. I wanted to use it in my mingw projects so i modified the source code to compile in both mingw and visual C++.

Great, I'll add the download link to the first post. Thanks ! I think the next release should compile in MinGW, thanks to the tips You shared ;)

I think there is some sort of stack corruption with gm::script_execute() in GM 6.1

Sometimes it crashes, sometimes it works, sometimes it freezes and uses 50% of my CPU. If i change some code in a completely unrelated area it will work, or it will break. All the other functions work (like gm::show_message or something) but gm::script_execute is buggy.

Hm, I'll take a look at this.

void ds_map_exists( const int id, const CGMVariable& key );

Fixed ;p

I was wondering if anybody could help me with this problem, it seems that VC++ doesn't know how to handle versions, having Debug compile fine but Release failing with incompatible versions.

As Icuurd said, recompiling GMAPI should do the job.
  • 0

http://sgames.ovh.org/ - my blog (Polish)

Game Maker projects:
- GMAPI - C++ library for DLL developers that directly accesses various game resources
- GMThreads - Library for Game Maker that allows you to execute GML code in a thread
- Game Protector [PL] - Protects games made in GM5/6.1/7.0 from decompiler
- GM Extractor [PL] - Dumps resources embedded in Game Maker project file to a selected directory
Other projects:
- MemExtractor [PL] - Extracts various resources from the process memory
- OllyDataInterpret [PL] - A plugin for OllyDbg 1.10 that shows different interpretations of selected data in a seperate window.


#48 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 10 October 2009 - 11:56 PM

Is there any news on this? Some more documentation would be nice. :)
  • 1

#49 39ster

39ster

    GMC Member

  • GMC Member
  • 898 posts

Posted 13 October 2009 - 11:53 AM

Maybe you could add an interfaces for particles and particle systems? It would be cool to be able to iterate through each individual particle within a system and do things such as collision checking against particles.
  • 0

#50 Houdini

Houdini

    GMC Member

  • New Member
  • 195 posts

Posted 12 November 2009 - 01:58 AM

Does any anyone know how to use GMAPI to create a new local variable on an object? I see how you can retrieve and set existing local variables, but not how you can create new ones.

Thanks!

- Houdini
  • 0