Jump to content


Photo

Gmaker C/c++ Library V. 2


  • Please log in to reply
177 replies to this topic

#1 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 22 February 2009 - 03:13 AM

GMaker C/C++ Library V. 2

What can I do with this library?

It's basically meant to be used with Game Maker DLLs period, but it's greatest feature is to easily use any Game Maker function within your DLL!

Can I use this with my DLL?

Of course! No restrictions, no credit required.

May I compile this library for other languages?

That is exactly why I made it open-source. I want people to add things to it, and make it greater than it really is.
If your going to make a topic with your library, and you used mine, you should probably link to this topic somewhere in it, and make sure the source to your library is available to anyone.

In this version forward, it will be open source for anybody to convert it to other languages.
Actually, you can probably just include the .cpp and .h file and use it in any compiler with some syntax changes.

DLLs that use this library (PM me if you want yours added):

system.dll: Threading, assembly, and more.
GMModelEx: GM Model Extender
D3D Particle System: Fast particle system for 3D!
GMFMODSimple


The download link for the compiler-specific library is below:
MingW (Dev-C++): Download

Edited by X-tra Fear, 12 April 2009 - 04:09 AM.

  • 0

#2 coolsmile

coolsmile

    Programmer

  • New Member
  • 1346 posts

Posted 22 February 2009 - 03:31 AM

That's pretty nice, but how does it work exactly?
  • 0

#3 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 22 February 2009 - 03:42 AM

That's pretty nice, but how does it work exactly?


How the library works, or how using it works?
  • 0

#4 coolsmile

coolsmile

    Programmer

  • New Member
  • 1346 posts

Posted 22 February 2009 - 03:59 AM

How does the library work exactly?
  • 0

#5 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 22 February 2009 - 04:01 AM

How does the library work exactly?


It takes advantage of a list of functions the game keeps in memory, then calls the function using it's function pointer (found in that list).

Probably need a lot more details, but I don't feel like explaining it right now. :D

Edited by X-tra Fear, 28 February 2009 - 02:51 PM.

  • 0

#6 coolsmile

coolsmile

    Programmer

  • New Member
  • 1346 posts

Posted 22 February 2009 - 04:15 AM

Sounds simple enough :D just some calls to GetProcAddress
I'm suprised people didn't think of that before
  • 0

#7 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 22 February 2009 - 04:54 AM

Sounds simple enough :D just some calls to GetProcAddress
I'm suprised people didn't think of that before


You'd think. More complex than that. :P
  • 0

#8 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 22 February 2009 - 12:22 PM

Are you saying that GM has a the names of its script function in the clear so I can get its address as easilly as you show for show_message?

So I could do a

GMPROC* ds_list_add = (GMPROC*) GetGMProcAddress("ds_list_add");

or
GMPROC* d3d_mode_draw = (GMPROC*) GetGMProcAddress("d3d_mode_draw");


Anyway, a few tips

1) Have an init function which will get the prointers to all the functions when its called
2) define a function to match the gm function name
3) define the proper operators so the casts are seamless

example
GMPROC* pexecute_string;
GMPROC* pds_list_add;
GMPROC* pds_list_create;
GMPROC* pds_list_find_value;
GMPROC* pds_list_destroy;
...

export double DLLInit(char* exeName)
{ 
  GetSystemInfo(&systemInfo);
  asmPointer = 0;
  
  // Get Game Maker version
  GMVersion = GetGMVersion();
  if(!GMVersion)
  {
	MessageBox(0, "This dll is incompatible with this version of Game Maker!", "System", 16);
	return false;
  }
  
  // Get Game in debug mode
  debugMode = GetGMDebugMode();
  
  // Get the pointer to execute_string
  pexecute_string = (GMPROC*) GetGMProcAddress("execute_string");
  pds_list_add = (GMPROC*) GetGMProcAddress("pds_list_add");
  pds_list_create = (GMPROC*) GetGMProcAddress("pds_list_create");
  pds_list_find_value= (GMPROC*) GetGMProcAddress("pds_list_find_value");
  pds_list_destroy= (GMPROC*) GetGMProcAddress("pds_list_delete");
  
  return true;
}

GMVariable gm_ds_list_add(GMVariable l, GMVariable v)
{
  GMVariable args[2];
  args[0] = l;
  args[1] = v;
  return GMProcCall(pds_list_add, 2, args);
}

GMVariable gm_ds_find_value(GMVariable l,GMVariable ind)
{
   GMVariable args[1];
   args[0] = l;
   args[1] = ind;
   return GMProcCall(pds_find_value, 1, args);
}

GMVariable gm_ds_list_create()
{
  return GMProcCall(pds_list_create, 0, NULL);
}

GMVariable gm_ds_list_destroy(GMVariable l)
{
  GMVariable args[1];
  args[0] = GMVariableCreate(mess);
  return GMProcCall(pds_list_destroy, 1, args);
}


now, in my c++ code I call stuff looking close to what it looks like in GML

double lid = gm_ds_list_create();
gm_ds_list_add(lid,1);
gm_ds_list_add(lid,2.2);
gm_ds_list_add(lid,"Another Item");

double v1 = gm_ds_list_find_value(lid,0)
double v2 = gm_ds_list_find_value(lid,1)
char *v3 = gm_ds_list_find_value(lid,2)

gm_ds_list_destroy(lid);


Oh, BTW, I dont want to go through execute_string to do my fiddling... That would turn out to be just as slow as calling execute_string in GM which would nullify the use of the dll as far as using it to improve performance.

Edited by icuurd12b42, 22 February 2009 - 12:38 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


#9 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 22 February 2009 - 05:01 PM

Well, you could probably simplify that more... did you see the example that came with it?

If you want to call them by their pointers, you could try this, althought it is a bit more messier.

GMPROC* ds_list_create = (GMPROC*) GetGMProcAddress("ds_list_create");
GMVariable ret = GMVariableCreate();
asm("mov $0x00, %ecx");
ds_list_create(&ret, 0, NULL);
return ret.real_part;

That would return a double... I don't see why you can't just use the GMProcCall function, since it handles everything for you and it works 100% of the time. Plus, it's written in full ASM and I realy don't want to make things harder for people, let alone them have 100 spots with 15 lines of the same asm everywhere.
  • 0

#10 score_under

score_under

    Least kawaii

  • GMC Member
  • 1321 posts

Posted 22 February 2009 - 06:13 PM

GMPROC* ds_list_create = (GMPROC*) GetGMProcAddress("ds_list_create");
GMVariable ret = GMVariableCreate();
asm("mov $0x00, %ecx");
ds_list_create(&ret, 0, NULL);
return ret.real_part;

Except that it will not work for execute_string() using this method :) And also, you've forgotten the order of the arguments again!
  • 0

Anti-Decompiler for GM6.1 to GM8.1.91! :GM8_new: [Main skin by Sindarin]
Discontinued.

decimal2.png
^ Signature image because it's been sorta empty since the old host died

If you need to contact me, I still get notification emails from PMs.


#11 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 22 February 2009 - 09:04 PM

I don't see why you can't just use the GMProcCall function, since it handles everything for you and it works 100% of the time. Plus, it's written in full ASM and I realy don't want to make things harder for people, let alone them have 100 spots with 15 lines of the same asm everywhere.


I don't understand why you said this from my post as my suggestion uses GMProcCall ...

I Asked
1) Do I have access to All GM Function?
2) Can you simplify it so it looks more like GM by providing the proper oveloaded operators so that the suggested function wrapper would look like those in my example...

I guess it's not a good idea to make the init create all the pointers since you will never need them all so an easy setup like my example definitions would help. All I would need is add the global variables in the init and add my function wrappers. Prety much like we do to define a external call in gm...

I see no reason to waste grabing the GMPointer GetGMProcAddress("ds_list_create"); each time you call a wrapper script. The wrapper script, a few examples covering each possibility (multi args, strings and so on) would help us define the appropriate scripts.

Edited by icuurd12b42, 22 February 2009 - 09:11 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


#12 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 23 February 2009 - 12:41 AM

I don't see why you can't just use the GMProcCall function, since it handles everything for you and it works 100% of the time. Plus, it's written in full ASM and I realy don't want to make things harder for people, let alone them have 100 spots with 15 lines of the same asm everywhere.


I don't understand why you said this from my post as my suggestion uses GMProcCall ...

I Asked
1) Do I have access to All GM Function?
2) Can you simplify it so it looks more like GM by providing the proper oveloaded operators so that the suggested function wrapper would look like those in my example...

I guess it's not a good idea to make the init create all the pointers since you will never need them all so an easy setup like my example definitions would help. All I would need is add the global variables in the init and add my function wrappers. Prety much like we do to define a external call in gm...

I see no reason to waste grabing the GMPointer GetGMProcAddress("ds_list_create"); each time you call a wrapper script. The wrapper script, a few examples covering each possibility (multi args, strings and so on) would help us define the appropriate scripts.


1. Yes, you have access to all functions.
2. Huh? Explain a bit.

You probably should grab the pointer in an init... that was just an example, and I didn't feel like writing an init.


I think I understand a bit what you're trying to say, but at the same time, I don't. :D
Just give me a little code example to show what you mean... oh wait, like if you put:

GMVariable a = GMVariableCreate(5.5);
double b = a;

b would = 5.5? Instead of having to do everything else.

EDIT: read your post earlier wrong. Yeah, I see what you mean now, exactly what I said. :) (I think).

Edited by X-tra Fear, 23 February 2009 - 12:58 AM.

  • 0

#13 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 23 February 2009 - 01:41 AM

If people are going to say something is C++, they should actually make use of some of the abstraction features of C++ to make the code actually easier to work with. If you're not using any features of C++, you're using C, period. You could pretty easily create a class which acts just like values in GM do (being able to assign strings to them and switch them to doubles later and have them automatically convert themselves into doubles or strings when retrieving values). C++ has some very powerful abstraction features and I'm disappointed that people who "use" C++ don't actually use the best of its features.
  • 0

#14 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 23 February 2009 - 02:27 AM

If people are going to say something is C++, they should actually make use of some of the abstraction features of C++ to make the code actually easier to work with. If you're not using any features of C++, you're using C, period. You could pretty easily create a class which acts just like values in GM do (being able to assign strings to them and switch them to doubles later and have them automatically convert themselves into doubles or strings when retrieving values). C++ has some very powerful abstraction features and I'm disappointed that people who "use" C++ don't actually use the best of its features.


There you go X-tra Fear...


If you change your struct to an actual Class, you can overload the/a few assignment operator(s) (Though can you define operators whitout the need to define a class?) I'm a straight C guy myself so I cant help much on that when it come to the C++ tricks.. But I know you can set it up the way I mentioned

so you can have

GMVariable a = 1.5;
or
GMVariable a = "Hello"

and

GMVariable func(GMVariable arg1)

that can be called like so

double ret = func("Hello");

or

char *ret2 = func2(4.5);

I think I understand a bit what you're trying to say, but at the same time, I don't.
Just give me a little code example to show what you mean... oh wait, like if you put:


Yourself would be very much more qualified to show you how to setup your class so it works as I decribed in my prior post... All you need is about 10 extra lines of code in your gmhelper h file and your c++ file...


also, I think you can shortcut a few things

GMVariable gm_ds_find_value(GMVariable l,GMVariable ind)
{
GMVariable args[2];
args[0] = l;
args[1] = ind;
return GMProcCall(pds_find_value, 1, args);
}

is possibly the same as
GMVariable gm_ds_find_value(GMVariable l,GMVariable ind)
{
GMVariable args[] = {l,ind };
return GMProcCall(pds_find_value, 2, args);
}

and possibly
GMVariable gm_ds_find_value(GMVariable l,GMVariable ind)
{
return GMProcCall(pds_find_value, 2, {l,ind });
}

You can make GMProcCall take multiple arguments using some method I forgot... Just like sprintf takes multiple arguments

double l = GMProcCall(pds_ds_list_create);
GMProcCall(pds_add_value,l,"hello#how#are#you");
GMProcCall(pds_add_value,l,1.4);
double t = GMProcCall(pds_find_value,l,1);
char *s = GMProcCall(pds_find_value,l,0);
char *fs = GMProcCall(pstring_replace_all,s,"#","\r\n");

Edited by icuurd12b42, 23 February 2009 - 02:50 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


#15 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 23 February 2009 - 03:31 AM

(Though can you define operators whitout the need to define a class?)


Yes, overloaded operators don't have to be members of a class. This allows you to add operators on to classes that someone else has made without putzing around in their code. For example:

classA& operator=(classA& a, double val) {
	a.real_part = val;
	return a;
}

This will create an overloaded assignment operator for assigning a double to an instance of classA. It returns a reference to the first argument so you can chain up assignments. This applies to structs too (in C++ the only difference between structs and classes is that the default access modifier is private for classes and public for structs).

Now there are some "operators" which must be members. For example, if you want to make your class automatically convert itself to a native type you must create a member method.

class classA {
	// Other stuff
	double real_part;
public:
	operator double() { return real_part; }
};

Now when C++ encounters a situation where it expects a double but instead gets an instance of classA, it will invoke the operator double method (which could really do just about anything as long as it returns a double).

You should also write a class to encapsulate the calls to GM functions and return an instance of that instead of these pointers which have to be passed to a special calling function.
  • 0

#16 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 23 February 2009 - 04:24 AM

Yeah, to late, got the code to work like how he said now...

only one thing left to go.

for some reason
GMVariable a = 5;

i suppose that could be like GMVariable::GMVariable(double a)

doesn't work, need to research on that...
going to switch to a class so ppl will stop *****ing.

You can make GMProcCall take multiple arguments using some method I forgot... Just like sprintf takes multiple arguments


va_list

Edited by X-tra Fear, 23 February 2009 - 04:29 AM.

  • 0

#17 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 23 February 2009 - 05:52 AM

GMVariable a = 5;



That would be this in your h file
GMVariable & operator=(GMVariable & a, double val) {
a.real_part = val;
return a;
}
  • 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


#18 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 23 February 2009 - 05:56 AM

If the class has a constructor taking a double, then the following will work:

classA myA = 5;

So will this.

classA myA;
myA = 5;

However, in many cases the former code will be slightly more efficient (assuming there is no appropriately overloaded assignment operator it will typically be even more efficient). The reason for this is a little bit complicated (and the following explanation leaves out some other details about what C++ is actually doing). When you declare the variable, C++ has to create an instance of the class. To do this it invokes the class constructor on the instance to initialize it. In the former piece of code the compiler can optimize the result so that the assignment ends up acting like an explicit construction (as in the value gets passed directly to the constructor). The latter however calls the constructor first which sets up the instance before seeing the assignment. If no assignment operator has been overloaded then C++ will try to convert the value 5 into a temporary instance of classA (for which a default assignment operator exists). It then copies from the temporary instance to the left side of the assignment. This is generally always slower than defining your own assignment operator (especially if the class has other data members that take time to construct/copy; a custom assignment operator will modify the instance in place rather than allowing C++ to create an unnecessary temporary object and copy over all of its data members).

You can make GMProcCall take multiple arguments using some method I forgot... Just like sprintf takes multiple arguments


You'll need to pass the number of arguments given to the function somehow. None of the standard calling conventions give a way for the called function to figure out the actual number of arguments that were passed (the caller has to pass some kind of indicator which the function knows to look for, in the case of sprintf the format string gives the function enough information to deduce the number and type of arguments, since each argument can be a different size in memory).
  • 0

#19 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 23 February 2009 - 06:02 AM


Would the simple reason it does not work, assuming he tried and implemented it correclty, is that the compiler will not automatically cast a int (5) to a double? In which case he would need to add a int version for the operator or constuctor...

and 1.1, if used as a value, would that default to a float in the compiler... again the compiler would not know to cast to a double...
  • 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 Yourself

Yourself

    The Ultimate Pronoun

  • GMC Elder
  • 7352 posts
  • Version:Unknown

Posted 23 February 2009 - 06:26 AM


Would the simple reason it does not work, assuming he tried and implemented it correclty, is that the compiler will not automatically cast a int (5) to a double? In which case he would need to add a int version for the operator or constuctor...

and 1.1, if used as a value, would that default to a float in the compiler... again the compiler would not know to cast to a double...


He'd have to be using a really ****ty compiler. Modern compilers are more than smart enough to figure out what type to turn a literal into.
  • 0

#21 Hach-Que

Hach-Que

    RoketGames Admin

  • New Member
  • 1490 posts

Posted 23 February 2009 - 06:33 AM

An important question I'd like to ask is, how fast can I get an image from a DLL into a Game Maker surface with this (if at all possible)?
  • 0

I don't visit these forums (and I haven't for quite some time). You can

see my latest community projects at the Redpoint Blog.


I never thought I'd see myself writing the above.. :(


#22 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 23 February 2009 - 07:21 AM

An important question I'd like to ask is, how fast can I get an image from a DLL into a Game Maker surface with this (if at all possible)?


You would have to convert the image (bmp) to a format acceptable by the draw_sprite command less you be forced to draw the image pixel by pixel

The guy who made this
http://gmc.yoyogames...hp/t397947.html
Could possibly know the answer..

Less you be able to get the DC of the surface directly from GM if it's a DC or it may be a directdraw handle or some other type of directx resource... Then you could draw right on on is with directx calls..

Having direct access to the directx resources created and used by GM would also be of great help in order to avoid having to go through GM's standard functions... Such has having to add a sprite to the sprite resource in order to draw it in the gm space.
  • 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


#23 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 23 February 2009 - 08:43 AM

Having direct access to the directx resources created and used by GM would also be of great help in order to avoid having to go through GM's standard functions... Such has having to add a sprite to the sprite resource in order to draw it in the gm space.

Its quite simple to hook Direct3DCreate(8/9)() to get the the iD3D(8/9) interface and then hook id3d8::CreateDevice() to get the Direct3D(8/9) Device pointer, which is used by every d3d app to render stuff load pixel/vertex shaders, etc etc.
If someone wants, I could release an example.

Edited by freaked, 23 February 2009 - 08:46 AM.

  • 0

#24 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 23 February 2009 - 09:02 AM

Having direct access to the directx resources created and used by GM would also be of great help in order to avoid having to go through GM's standard functions... Such has having to add a sprite to the sprite resource in order to draw it in the gm space.

Its quite simple to hook Direct3DCreate(8/9)() to get the the iD3D(8/9) interface and then hook id3d8::CreateDevice() to get the Direct3D(8/9) Device pointer, which is used by every d3d app to render stuff load pixel/vertex shaders, etc etc.
If someone wants, I could release an example.


Go ahead... It would complement this dll I think
  • 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


#25 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 23 February 2009 - 10:03 PM

Oh, I have been working on the library, and have redone it entirely. :o

Go ahead... It would complement this dll I think


This is a library, not a dll. ;P
The example is a dll though. ^^

Anyway, you can do it like this in the one I'm working on:

GMPROC* pshow_message;

void init()
{
  pshow_message = (GMPROC*) GetGMProcAddress("show_message");
}

GMVariable show_message(GMVariable message)
{
  GMVariable args[] = { message };
  return GMExternalCall(pshow_message, 1, 0, args);
}

export double call(char* message)
{
  show_message(message);
}

Now, I'm looking into making it more like this:

GMPROC show_message;

void init()
{
  show_message = GetGMProcAddress("show_message");
}

export double call(char* message)
{
  show_message(1, message); // 1 is the args used
}

But I don't think you can use a class as a function... if anyone knows how to, by all means, tell me now. ^_^


If the first one is fine with everybody, I'll release it now. Otherwise, I'll look into the second one...

GMVariable has been beefed up a bit, too.

GMVariable a = 5;
GMVariable b = "Hey!";
GMVariable c = 7;
double d = a + b;
char* e = b;

Some examples. ^

Edited by X-tra Fear, 23 February 2009 - 10:21 PM.

  • 0

#26 Mnementh

Mnementh

    15151

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

Posted 23 February 2009 - 10:08 PM

But I don't think you can use a class as a function... if anyone knows how to, by all means, tell me now. :o

Was that a joke? How can you know C++, and not know how to use operator overloading?

While you're at it, if you're going to encapsulate this anyway, then there's really no reason to have a separate function that serves the purpose of a constructor. Just give your GM function class a constructor that takes a string, have the class itself do the work.

And if you're going to add "GM" to the beginning of everything you make, then you might as well create a namespace to put all of this in, and make it easier to work with.

Edited by Mnementh, 23 February 2009 - 10:12 PM.

  • 0

#27 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 23 February 2009 - 10:10 PM

Will release soon...

Edited by X-tra Fear, 24 February 2009 - 11:33 AM.

  • 0

#28 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 23 February 2009 - 11:21 PM

Will you release the uncompiled source for this? Ever?
  • 0

#29 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 24 February 2009 - 12:14 AM

You're on your way... Just be patient with the perfectionists...
  • 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


#30 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 24 February 2009 - 07:12 AM

Compile as Dll.
Inject with Winject into a game maker game.
[huge code]
[codebox]// d3dhook.cpp : Defines the entry point for the console application.
//
#define msg(text) MessageBoxW(0,text,L"D3DHOOK",0)

#include "stdafx.h"
#include <windows.h>
#include "define.h"
#include <detours.h>
#include <d3d8.h>
#pragma comment(lib,"detours.lib")
#pragma comment(lib,"d3d8.lib")


void HookCreateDevice();
void HookDirect3DCreate8();

IDirect3D8* g_interface;
IDirect3DDevice8* g_device;



IDirect3D8* (__stdcall *oDirect3DCreate8)(UINT version);
IDirect3D8* __stdcall hkDirect3DCreate8(UINT version)
{
__asm nop;
MessageBox(0,L"D3DCreate8 called -- d3dhook",L"D3DHOOK",0);
g_interface = oDirect3DCreate8(version);
HookCreateDevice();
return g_interface;
}

HRESULT (__stdcall *oCreateDevice)(IDirect3D8* me,UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice8 **ppReturnedDeviceInterface);

HRESULT __stdcall hkCreateDevice(IDirect3D8* me,UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice8 **ppReturnedDeviceInterface)
{
__asm nop;
MessageBox(0,L"CreateDevice()called! -- d3dhook",L"D3DHOOK",0);
HRESULT hr = oCreateDevice(me,Adapter,DeviceType,hFocusWindow,B
ehaviorFla
gs,pPresentationParameters,ppReturnedDeviceInterfa
c
e);
g_device = *ppReturnedDeviceInterface;
return hr;
}








void HookDirect3DCreate8()
{
MessageBox(0,L"HookingDirect3DCreate8",L"D3DHOOK",0);
oDirect3DCreate8 = (IDirect3D8 *(__stdcall *)(UINT))DetourFunction((PBYTE)GetProcAddress(Load
Library(L"d3d8.dll"),"Direct3DCreate8"),(PBYTE)hkDirect3DCreate8);

}

void HookCreateDevice()
{
MessageBox(0,L"Hooking CreateDevice() now",L"D3DHOOK",0);
DWORD* pdwNewInterface = (DWORD*)g_interface;
pdwNewInterface = (DWORD*)pdwNewInterface[0];
MessageBox(0,L"PEnter to Install Hook",L"",0);
oCreateDevice =(HRESULT (__stdcall *)(IDirect3D8 *,UINT,D3DDEVTYPE,HWND,DWORD,D3DPRESENT_PARAMETERS *,IDirect3DDevice8 **)) DetourFunction((PBYTE)pdwNewInterface[15],(PBYTE)h
kCreateDevice);
}

/*

*
*
*
* DLLMAIN
*
*
*
*/
bool __stdcall DllMain(HMODULE hHand,DWORD dwReason,LPVOID lpReserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
//DisableThreadLibraryCalls(hHand);
MessageBox(0,L"Hook Injected",L"D3DHOOK",0);
HookDirect3DCreate8();
//HookCreateDevice();



case DLL_PROCESS_DETACH:
//MessageBoxW(0,L"Exit",L"Exit",0);
GetForegroundWindow();
}
return TRUE;
}[/codebox]
[/huge code]
[Edit]Updated to use code-box

Edited by freaked, 24 February 2009 - 09:57 AM.

  • 0

#31 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 24 February 2009 - 11:35 AM

I'm sticking to wrapping the calls like external_call in GM.

Unless you want to cast every argument like this (GMVar)(GmVariable) 5 ;P

Going to try to get a newer version up before I go to school in 10 mins... later.

@ the guy above
I'll try to add a simple way to get it into the library using that. :)

I added a export thing in the GMaker.h file so you won't need to define anything.

Will you release the uncompiled source for this? Ever?


You think I really want to hear anybody else bash my code?
I'll think about it.

EDIT: Will be releasing the updated version within an hour. :o
There are a few major changes, it should be easier to work with now, and I even provided an example using show_message(string(number)); -_-

Edited by X-tra Fear, 24 February 2009 - 09:13 PM.

  • 0

#32 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 24 February 2009 - 09:58 PM

UPDATE

And double post. x.x

Edited by X-tra Fear, 24 February 2009 - 09:58 PM.

  • 0

#33 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 24 February 2009 - 10:23 PM

I can't see why you people still want to use C++ for the job, you'll end up recreating most of the vcl/rtl.
Why not just use Delphi with some typcasting? I've got this working in much less dirtier C++ code.
  • 0

#34 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 24 February 2009 - 10:24 PM

I can't see why you people still want to use C++ for the job, you'll end up recreating most of the vcl/rtl.
Why not just use Delphi with some typcasting? I've got this working in much less dirtier C++ code.


That's cool.

Got what working?

EDIT: Sorry, misread it. :)
What does the _your_ mean when it has __ with it? :S

EDIT2: Ah, gotcha. :o

EDIT3: Nvm, lol. xD

Edited by X-tra Fear, 24 February 2009 - 10:34 PM.

  • 0

#35 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 24 February 2009 - 10:25 PM

I'm not saying anything about _your_ code. I'm talking about the choice of language.
Would you debug PHP with a disassembler?

Edit:
1) Pointer playing
2) That's to show the focus of my message :)
Edit:
Huh?!

Edited by uuf6429, 24 February 2009 - 10:32 PM.

  • 0

#36 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 25 February 2009 - 06:28 AM

Very good... Now I can update a few of my dlls
  • 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 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 25 February 2009 - 07:58 PM

Very good... Now I can update a few of my dlls


I'm glad somebody wants to use it... :whistle:
  • 0

#38 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 25 February 2009 - 11:02 PM

Well, at least people could learn some real stuff. I highly doubt it though.
  • 0

#39 PickleMan

PickleMan

    Programmer

  • New Member
  • 995 posts
  • Version:Unknown

Posted 25 February 2009 - 11:14 PM

Nice. The only problem is: Why the hell would someone be using GM functions in C++ if they could eaisly make a faster version in C++, and why not just switch completely to C++?

Stuff like this is kinda distorting the original intention of GM. "...You can make a game without any code!..." "...Its aimed at beginners..."
  • 0

#40 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 26 February 2009 - 12:40 AM

Nice. The only problem is: Why the hell would someone be using GM functions in C++ if they could eaisly make a faster version in C++, and why not just switch completely to C++?

Stuff like this is kinda distorting the original intention of GM. "...You can make a game without any code!..." "...Its aimed at beginners..."


If want to have a jello 3d model... you can't morph the points fast enough. So you move that code in a dll

If you want to fiddle a grid, average them to emulate wind... Again, move the code to a dll...

If you want to quick draw a surface biit by bit, morphing it so it looks like watter... Again GML is too slow... Move the code to a dll.

If you want to pass a laerge amout of data back and forth, a ds_list or map is the only way to go... You need to acces GM's data structure in the dll to do that.

If you don't see the use of this it's your lack of imagination. I've been needing this in the first GM dll I ever made. It's so obvious we need this from day 1.

This open up the possibility for GM addons that are 1000 times more powerful than a freaking dll with APIs passing a limited number of doubles and strings. A single API call can update GM data without the need to translate information... Like (right now) calling a API 3000 time to get 1000 x,y,z points...
  • 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


#41 mechanikos

mechanikos

    GMC Member

  • New Member
  • 453 posts

Posted 26 February 2009 - 01:27 AM

A single API call can update GM data without the need to translate information.


Are you sure about that? A dll can change GM data from within the dll, without the dll ending and returning?

As I recall, such schemes has been discussed before, and rejected as being inherently destabilizing to GM.

I don't know though, I'd like to hear discussion about this.
  • 0

#42 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 26 February 2009 - 01:38 AM

To be honest, I think icuurd12b42 just pointed out some of the best reasons to use this library.

:whistle:

As for what you said, mechanikos, I'm really not sure.
  • 0

#43 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 26 February 2009 - 01:38 AM

A single API call can update GM data without the need to translate information.


Are you sure about that? A dll can change GM data from within the dll, without the dll ending and returning?

With this it can, before that you could not unless you know something I don't.

As I recall, such schemes has been discussed before, and rejected as being inherently destabilizing to GM.

I don't know though, I'd like to hear discussion about this.


The only destabilizing factore I can see is if GM7.2 comes out... You'd have to calculate a new offset for the functions lookup.
  • 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


#44 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 26 February 2009 - 01:51 AM

Oh, I think I forgot to say... you don't need to define an export in the newer version. :whistle:
You can just put "export" behind any function, and your good to go after you include GMaker.h.

The only destabilizing factore I can see is if GM7.2 comes out... You'd have to calculate a new offset for the functions lookup.


Yeah, only thing I can see too.

Edited by X-tra Fear, 26 February 2009 - 01:54 AM.

  • 0

#45 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 26 February 2009 - 01:19 PM

That's easy though...we don't expect GM 7.2 (or whatever) any time soon. Plus, GM versions can be counted on one hand.
  • 0

#46 WadeMcGillis

WadeMcGillis

    wademcgillis.com

  • GMC Member
  • 971 posts

Posted 27 February 2009 - 02:27 AM

To be honest, I think icuurd12b42 just pointed out some of the best reasons to use this library.


Another "best reason": You can now make a game more decompiler proof. Just put GML into the DLL and no one would be able to really know what code is being executed.

That's easy though...we don't expect GM 7.2 (or whatever) any time soon. Plus, GM versions can be counted on one hand.


HOW MANY FINGERS DO YOU HAVE?!?!?!?
  • 0

#47 Marchal_Mig12

Marchal_Mig12

    The Rhouan

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

Posted 27 February 2009 - 06:12 AM

I am trying to figure out whats the benefit of calling GM's functions through a dll but I can't. Could anyone tell me what results I can get from this?

Thanks,

Miguel

EDIT: Now I understand. Could it be possible to move an object in game maker's through the dll without getting this object's position from the dll and then updating the position?

Edited by Marchal_Mig12, 27 February 2009 - 06:15 AM.

  • 0

#48 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 27 February 2009 - 07:30 AM

EDIT: Now I understand. Could it be possible to move an object in game maker's through the dll without getting this object's position from the dll and then updating the position?


That would be the next BIG trick!!
  • 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


#49 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 27 February 2009 - 12:58 PM

@Marchal_Mig12:
The benefit should only exist when using direct GML functions only. You can call functions directly without having to have the code interpreted then called. It should give some speed.

There is a massive difference between the functions and variables. Someone could try to use execute_string but they may say it's a bit slower. But have people forgot of the actual functions for this? The only issue I can think of is the local variables, they are object specific and need to be called from the object. It may be possible if it's called from the object.
variable_global_get(name)
variable_global_set(name, value)
variable_local_get(name)
variable_local_set(name, value)
etc.

  • 0

#50 Marchal_Mig12

Marchal_Mig12

    The Rhouan

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

Posted 27 February 2009 - 05:53 PM

EDIT: Now I understand. Could it be possible to move an object in game maker's through the dll without getting this object's position from the dll and then updating the position?


That would be the next BIG trick!!


That would! I guess it cant? What if I call move_bounce_all() function through the dll? Is the object going to bounce?
  • 0