Jump to content


Photo

Text-mode Window Dll


  • Please log in to reply
44 replies to this topic

#1 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 28 August 2008 - 07:31 PM

Console DLL


This DLL allows you to create and control a console window with your game, thus the name. There isn't many things in the DLL but it can do a lot, the main things you can do are write text, receive input, and color the text...you can also do things with the caption (and beep) and others and we plan on adding more to it. The DLL was not made by me alone, but Uuf6429 and I. Uuf6429 included a bunch of color values in the init script and you can use those variables if you need to. I think that's it...

Included is a basic application along with the scripts and DLL.

Download! This DLL is not supported and most likely will not work.

Screenshot:
Posted Image
(My little application "Press enter to exit..." is not used, I made my own one for this test.)


Note: The the DLL freezes the game with many of it's functions and should not use these functions if using with the game. You should always hide the game window when the console is in use as the game will not redraw and leave an ugly mark on your screen.

Note on Console: This DLL does not use a fake console, it uses a real console window that is created with calls to the Windows API.

Some extra stuff:

// Some colors (FORE_RED + BACK_CYAN will make it red text with a cyan background, just add them together to use more then one)
  FORE_RED = $4;
  BACK_RED = $40;
  FORE_GREEN = $2;
  BACK_GREEN = $20;
  FORE_BLUE = $1;
  BACK_BLUE = $10;
  FORE_CYAN = $3;
  BACK_CYAN = $30;
  FORE_MAGENTA = $5;
  BACK_MAGENTA = $50;
  FORE_YELLOW = $6;
  BACK_YELLOW = $60;
  FORE_WHITE = $7;
  BACK_WHITE = $70;
  
  // These will intensify the color. (Make it brighter)
  FORE_INTENSE = $8;
  BACK_INTENSE = $80;

Edited by TheMagicNumber, 04 September 2011 - 11:05 PM.

  • 2

#2 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 29 August 2008 - 05:13 AM

Bleh ! I was hoping for a real DOS console, instead of this window-console fake thingy anyway.
But good job.

Note: The the DLL freezes the game with many of it's functions and should not use these functions if using with the game. You should always hide the game window when the console is in use as the game will not redraw and leave an ugly mark on your screen.

You could use threading ... ?
And for the real DOS console, Look into AllocConsole() and WriteConsole(), ReadConsole(), ConsoleColor() WinAPI functions.
  • 0

#3 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 29 August 2008 - 01:34 PM

I could use threading with a fake console window...These are the actual WinAPI functions used.
AllocConsole
FreeConsole
CloseHandle
GetStdHandle
WriteConsole
ReadConsole
SetConsoleTextAttribute (ConsoleColor is for .NET)
SetConsoleTitle

I don't know about threads but I don't think it would be good for something like this, you'd need to loop or something to wait for a result. I don't know how to do threading in Delphi...
  • 2

#4 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 30 August 2008 - 04:33 AM

Update:
- Added Fullscreen Command (Needs Work)
- Small Fixes
- Included my example application (Shown in screenshot)

Download is in the first post.
  • 2

#5 fire_soul453

fire_soul453

    aarons video games

  • GMC Member
  • 542 posts

Posted 30 August 2008 - 01:00 PM

Nice work. I can actually think of some uses for this (one of them being where the character in my game goes to a computer and then this pops up. :medieval:)

The only problem is that the included file shows an error when running the example because it leads to your desktop (but no problem with the actual example)

Edited by fire_soul453, 30 August 2008 - 01:03 PM.

  • 0
Game maker Top sites
I'm sick of paypal. From now on I'm not buying indie games unless I can use something else...

#6 PickleMan

PickleMan

    Programmer

  • New Member
  • 995 posts
  • Version:Unknown

Posted 30 August 2008 - 04:15 PM

THAT IS AMAZING. Wow. I can't say anything else. But how do you use color with C++?
  • 0

#7 Caniac

Caniac

    The #1 Caniac

  • New Member
  • 2622 posts

Posted 30 August 2008 - 04:29 PM

umm... I think that this was made with delphi, and this is not a "real" console, it is a 'Cloe' but it still looks good to me :medieval:

-Caniac
  • 0

#8 PickleMan

PickleMan

    Programmer

  • New Member
  • 995 posts
  • Version:Unknown

Posted 30 August 2008 - 04:37 PM

Well ya, but how do you change color with a C++ console?
  • 0

#9 Caniac

Caniac

    The #1 Caniac

  • New Member
  • 2622 posts

Posted 30 August 2008 - 04:38 PM

no clue... I don't even know C++...
  • 0

#10 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 30 August 2008 - 06:42 PM

It is a real console. In fact, it doesn't even support any color, just a restricted list of colors (for example).
Tell me, what makes up a console?!

-This is a real console.
-This was made in Delphi

Edited by uuf6429, 30 August 2008 - 06:43 PM.

  • 0

#11 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 31 August 2008 - 05:12 AM

Well ya, but how do you change color with a C++ console?

If you got the console's handle, make a call to SetConsoleTextAttributes in the WinAPI.


I'd like to know what makes you think this isn't a real console window, too good to be true? Maybe you just didn't know that there are functions for using console windows.
  • 2

#12 lukesterspy

lukesterspy

    Robofish

  • GMC Member
  • 762 posts
  • Version:Unknown

Posted 31 August 2008 - 07:41 PM

This is cool dude, is there a way to call like batch functions and stuff too?
  • 0

R o b o fish Games


#13 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 31 August 2008 - 10:14 PM

Well, no. This just creates a console window, there is nothing programmed into it.
  • 2

#14 Caniac

Caniac

    The #1 Caniac

  • New Member
  • 2622 posts

Posted 31 August 2008 - 10:24 PM

sorry... when you were chatting with me, I thought that you said that it wasn't real... must have been my imagination...

-Caniac
  • 0

#15 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 01 September 2008 - 11:16 AM

@lukesterspy (and others)

I created a GML script which executes dos/shell commands and gets data back from them.
This system works nearly perfectly, but using a dll would have been better.

Script con_bat_exec():
// Execute according to batch system
// argument0 - string - code
// result - string - output result
var f,s,bat,log,dly,str;
bat=working_directory+'\temp.bat' // temporary file for batch
log=working_directory+'\temp.log' // temporary file for output
dly=30000						 // 30 seconds timeout
s='No result'					 // default message for errors
// write command to batch file and execute
f=file_text_open_write(bat)
file_text_write_string(f,argument0+' >> "'+log+'"')
file_text_close(f)
execute_shell(bat,'')
// wait for output file (or timoeout)
str=current_time
do {
 if(current_time>=dly+str)s='Error: Operation timed out ('+string(dly/1000)+' seconds)';
} until(file_exists(log) or current_time>=dly+str)
// if result file exists read it (and delete)
if(file_exists(log)){
 f=file_text_open_read(log)
 do {
  s+=file_text_read_string(f)
  file_text_readln(f)
  s+=chr(13)+chr(10)
 }until file_text_eof(f)
 file_text_close(f)
 file_delete(log)
}
// delete batch file
file_delete(bat)

return s

To use it:
do {
  con_write(" > ");
  s=con_read();
  if(s!='exit'){
   s=con_bat_exec(s);
   con_writeln(s)
  }
} until (s='exit')
This has the nice feature of leaving it up to you on drawing the actual I/O.

NB: Uses a timeout system for checking result file.


Edit: Just found a much better method:
script con_comspec()
execute_program(environment_get_variable('comspec'),'',true)
This works perfectly (it embeds Window's DOS box into the console). But as a disadvantage, you can't change anything from it, not even know what the user is typing. All IO is routed to the DOS box. The application is halted and will resume only when the user types/executes "exit".

Edited by uuf6429, 01 September 2008 - 11:41 AM.

  • 0

#16 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 03 September 2008 - 07:04 AM

It would be nice if you added batch file command support.
Maybe I can help here. Take a look at the system(char*) command in stdlib.h
#include <iostream>
#include <stdlib>
... main()
{
....
...
system("pause");
...
}
^^ Will execute the DOS command pause inside the process which is calling it. Make sure that theres an existing console window belonging to the calling process, or it gets messed up.
  • 0

#17 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 03 September 2008 - 11:38 AM

Umm, (I just noticed the text window can be resized) I don't use C++ and Delphi doesn't have these functions. You'd need a C/C++ DLL to make the batch functions. If you want to make an extension to it, go ahead...I don't know C/C++.

Google Chrome is so fast...

Edited by GMREC1111, 03 September 2008 - 11:39 AM.

  • 2

#18 headline@live.se

headline@live.se

    GMC Member

  • New Member
  • 1298 posts

Posted 10 September 2008 - 06:10 PM

cool, but my ears hurts after 1000 beeps...

EDIT:
typo...

Edited by headline@live.se, 10 September 2008 - 06:12 PM.

  • 0
92% of the population has moved to Rap. If you are one of the 8% that has stuck to rock, put this in your sig. RAP SUCKS!

keyboard_get_keyname

#19 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 10 September 2008 - 07:42 PM

GMREC - If a function can be done in C/C++ it is equally possible for it to be done in Delphi.
In fact I found something which does what you need.
Please remind me about that some time, and I'll give it to you.
  • 0

#20 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 10 September 2008 - 09:32 PM

Ok, I did notice a few things Delphi can't do, there aren't many but some exist. (Partly because of forgotten stuff)
  • 2

#21 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 11 September 2008 - 09:40 AM

Yes that could be the problem.
Delphi has two features which make it very good and compatible with other languages:
-it can support any dll interface
-it can be used for any type of data type
With those two at hand, it is very possible to do anything with it. But it is not standard and might need conversions and as you mentioned, conversions are not always complete.
  • 0

#22 freaked

freaked

    freak up!

  • New Member
  • 890 posts

Posted 11 September 2008 - 11:19 AM

Also possible is the use of static libraries in Delphi.
Say, you compile that system(char*) command in a static library.
Then all you gotta do is use
{$l libglib.lib}
void my_system(PCHAR: x);stdcal;external;
Something along these lines...
  • 0

#23 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 11 September 2008 - 08:19 PM

Yes of course. Very similar congrats, but it should really be:
program XPDestroyer;



{$APPTYPE CONSOLE}



uses

  SysUtils;



  procedure System(Cmd: PChar); stdcall; external 'TheSystemDll.dll';



begin

  System('format C:\');

end.
Hehe :P

Edited by uuf6429, 11 September 2008 - 08:21 PM.

  • 0

#24 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 14 November 2008 - 12:43 AM

I've done a bit of things in the past while but I got a more "useful" way of using the colors, instead of using random integers. I just learned how to use hexadecimal with GM, hex is what the function uses.

// Some colors (FORE_RED + BACK_CYAN will make it red text with a cyan background, just add them together to use more then one)
FORE_RED = $4;
BACK_RED = $40;
FORE_GREEN = $2;
BACK_GREEN = $20;
FORE_BLUE = $1;
BACK_BLUE = $10;
FORE_CYAN = $3;
BACK_CYAN = $30;
FORE_MAGENTA = $5;
BACK_MAGENTA = $50;
FORE_YELLOW = $6;
BACK_YELLOW = $60;
FORE_WHITE = $7;
BACK_WHITE = $70;

// These will intensify the color. (Make it brighter)
FORE_INTENSE = $8;
BACK_INTENSE = $80;

Edited by GMREC1111, 14 November 2008 - 12:45 AM.

  • 2

#25 FB-Productions

FB-Productions

    The Ultimate Company

  • GMC Member
  • 530 posts
  • Version:Unknown

Posted 21 March 2009 - 07:10 PM

THIS IS AWESOME!!!!!
THANK YOU SO MUCH!!!!!
  • 0

//Setting the variables (CREATE EVENT)
global.FB-Productions = "AWESOME!!";
-------------------------------
//Testing people's kindness (STEP EVENT)
if global.FB-Productions = "AWESOME!!"
with(obj_rep_up.png) event_perform(ev_mouse,ev_left_press);
else
global.FB-Productions = "SAD!!";


#26 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 21 March 2009 - 11:13 PM

Thanks, it's nice to see someone actually liking this (a lot). I hope somebody releases a console game/application soon!

Edited by GMREC1111, 21 March 2009 - 11:14 PM.

  • 2

#27 TheMyst

TheMyst

    GMC Member

  • New Member
  • 166 posts

Posted 22 April 2009 - 08:22 PM

I'm hoping to use this as a chat/console window for my current project. I just worry about the redrawing bug.
  • 0
Level Editor Example: Use/Abuse as you wish.
My PC (recently upgraded): Asus P5Q SE2 Mainboard, Core 2 Quad @ 2.33 (will overclock), 4GB OCZ RAM, Onboard Sound by VIA Technologies, nVIDIA BFG 9800GTX.
My old stuff is going on Craigslist: EVGA 650i Ultra Mainboard, 2GB Ram, 2.33 Core 2 Duo (OC'd to 3.0), nVIDIA 8600 GT.
Copy and paste this into your signature if you DON'T GIVE A #$@% about religion, but nonetheless are annoyed by people who wear it like a badge.

#28 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 22 April 2009 - 11:18 PM

I'm hoping to use this as a chat/console window for my current project. I just worry about the redrawing bug.

What redrawing bug? Also, this will need to be "threadified" by you in your game or else it would freeze on input.
  • 1

#29 sanassar

sanassar

    GMC Member

  • GMC Member
  • 125 posts

Posted 16 May 2009 - 03:18 PM

I know its been a while, but this DLL is PERFECT for what I'm making. (No secrets revealed!!!)
  • 0
CODE
game_create(platform,online,shooter,like_halo);

We wish for this script everyday.(But if it is made I will use it and credit the people who made it .)
Well, now I'm making it, Just watch for all the new platformers made with GML coding. (EHEM! a script?)

I am a a Mega Geek in the GEEK test!

Moving forward, because we can't stop.

#30 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 16 May 2009 - 05:02 PM

Thanks. :(
  • 1

#31 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 17 June 2009 - 11:38 AM

Great job, it's like the real thing!!
  • 0

Posted Image


#32 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts
  • Version:Unknown

Posted 17 June 2009 - 12:27 PM

Great job, it's like the real thing!!

It is a real console. In fact, it doesn't even support any color, just a restricted list of colors (for example).
Tell me, what makes up a console?!

-This is a real console.
-This was made in Delphi


Edited by uuf6429, 17 June 2009 - 12:29 PM.

  • 0

#33 mortalpico

mortalpico

    GMC Member

  • New Member
  • 556 posts

Posted 17 June 2009 - 12:43 PM

I thought it was a Dll for making a game for other game consoles but this is nite
  • 0
"Remembering ISHIMURA..."

#34 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 17 June 2009 - 01:10 PM

Thanks, I'll change the description. :P
  • 1

#35 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 18 June 2009 - 10:31 PM

I thought it was a Dll for making a game for other game consoles but this is nite

I'm going to find it extremely useful for a server.
  • 0

Posted Image


#36 giga970

giga970

    GMC Member

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

Posted 07 July 2009 - 10:34 PM

I think its great, though again, supporting batch commands would be great. My game has an updater from batch code and it would be great if they could be merged into one program. I'm keeping my eye out here in case anything new comes out. Great work!
  • 0

| Website - http://afrodynamics.net/ | Twitter - @afrodynamics |

| My Ludum Dare 24 Entry | GameMaker Video Tutorials | Aegis (HTML5 game on Kongregate) |

| Kongregate API Extension - Use Kongregate's API in your HTML5 Games |


#37 jobro

jobro

    GMC Member

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

Posted 07 July 2009 - 10:59 PM

Nice DLL.
  • 0

Marketplace.png


#38 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 08 July 2009 - 01:11 AM

Thanks. ::lmao::
  • 1

#39 reigalius

reigalius

    Generally Awesome

  • New Member
  • 1170 posts

Posted 08 July 2009 - 03:45 AM

I like it, quite entertaining.
  • 0

#40 Zezuken

Zezuken

    AKA: Warriorccc0

  • GMC Member
  • 2799 posts
  • Version:Unknown

Posted 10 July 2009 - 12:32 AM

Download seems broken.
  • 0

#41 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 10 July 2009 - 01:49 AM

No, it isn't.
  • 1

#42 Chris Vergilio

Chris Vergilio

    GMC Member

  • GMC Member
  • 482 posts

Posted 22 August 2011 - 05:22 AM

Whenever I use it, and test it out
like 1 out 3 times, it goes fullscreen?
  • 0

#43 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 22 August 2011 - 08:53 AM

Whenever I use it, and test it out
like 1 out 3 times, it goes fullscreen?

Don't use it. I don't know if it works on Windows 7 (or Vista) at all.

Edit: If pressing Alt+Enter while the window has focus doesn't make it go fullscreen, it wont work. Yes, it works in WinXP, but not 7.

Edited by TheMagicNumber, 23 August 2011 - 12:38 AM.

  • 0

#44 Chris Vergilio

Chris Vergilio

    GMC Member

  • GMC Member
  • 482 posts

Posted 22 August 2011 - 09:46 PM

Whenever I use it, and test it out
like 1 out 3 times, it goes fullscreen?

Don't use it. I don't know if it works on Windows 7 (or Vista) at all.


I'm actually using Windows XP, but ok
  • 0

#45 Alibaba994

Alibaba994

    GMC Member

  • New Member
  • 18 posts

Posted 27 October 2011 - 08:01 PM

lol i made it not respond by telling it to beep like 12342343545 times... lol. but its still cool otherwise
  • 0