Acknex.exe with console

Posted By: Quad

Acknex.exe with console - 01/30/11 21:05

Some of you are going to love this

It is basically acknex.exe with console, which you can printf to, your plugins can printf to, even maybe engine functions can printf to.
Posted By: WretchedSid

Re: Acknex.exe with console - 01/30/11 21:09

Love you!
(No really, thanks mate)
Posted By: Dark_samurai

Re: Acknex.exe with console - 02/03/11 14:11

Wow that is great. But if this cant be used with published projects, it isn't possible to create for example a console based server application... But it is great for debuggin.
Posted By: Quad

Re: Acknex.exe with console - 02/03/11 14:17

I publishing does not want to work with the custom acknex.exe version, it's either probably because original acknex.exe does something extra i do not know or it's becuase of the command line args handling. Latter is not very likely though.
Posted By: rojart

Re: Acknex.exe with console - 02/06/11 02:11

Thanks, It will be helpful.
Is it possible to look at the source-code?
Posted By: Quad

Re: Acknex.exe with console - 02/06/11 02:17

yes, it's on the sdk_engine/acknex.cpp
Posted By: rojart

Re: Acknex.exe with console - 02/06/11 14:05

I mean the whole code with printf function, but I understand that, you don't want it to show here. wink
Posted By: Quad

Re: Acknex.exe with console - 02/06/11 14:35

ooh the full source of the printf.dll

Code:
#include "stdafx.h"
#include <stdio.h>

#ifdef __cplusplus
extern "C" {

#endif

__declspec( dllimport ) void cprintf(char *msg, ...);

#ifdef __cplusplus
}
#endif

void cprintf(char *msg, ...)
{
   va_list argList;
   va_start(argList, msg);

   vprintf(msg, argList);

   va_end(argList);
}


Posted By: rojart

Re: Acknex.exe with console - 02/06/11 14:59

Exactly, what I wanted to see, thanks again!
Posted By: Tempelbauer

Re: Acknex.exe with console - 02/14/11 19:45

You´re my Hero laugh
Posted By: SchokoKeks

Re: Acknex.exe with console - 07/08/11 22:03

Thats a great contribution,
would you mind sharing the changes you did to acknex.cpp to make it open a second window that displays the console?
that would probably save me a lot of hassle laugh
Posted By: Quad

Re: Acknex.exe with console - 07/08/11 22:27

There is no change in the source, only on project settings. Set it as console application instead of windows application and you are set.
Posted By: Rackscha

Re: Acknex.exe with console - 08/02/11 20:35

mh if publishing doesnt work with this technique, maybe create a second application, a logger application which can communicate through pipes with liteC? since we have winapi, we have pipes. Worked with them at work in delphi. It might be a bit complicated at first but allows them to use for logging(tools like smartinspect for example use them).

This way you can send messages between applications.

Greets
Rackscha
Posted By: alibaba

Re: Acknex.exe with console - 05/06/15 11:08

Sooo.. is this still around somewhere?
Posted By: Ch40zzC0d3r

Re: Acknex.exe with console - 05/06/15 12:23

Call AllocConsole and there it is.
You can google the API, it will be described further on msdn.
Posted By: alibaba

Re: Acknex.exe with console - 05/06/15 12:37

Sadly it won´t display any printf calls whatsoever. Is there a way to use the console to command the acknex engine? I need this to modify a dedicaded server in runtime.
Posted By: MasterQ32

Re: Acknex.exe with console - 05/06/15 12:54

if you have the console, try reading the stdin file via fread wink
Posted By: WretchedSid

Re: Acknex.exe with console - 05/06/15 12:58

You will love this!

You can redirect stdout to a virtual console file using freopen() like so:
Code:
freopen("CONOUT$", "w", stdout);



Redirecting the console to stdin works via the CONIN$ virtual file.

This, of course, does not work with the standard Gamestudio printf(), because standard gamestudio is stupid and doesn't actually ever output to stdout. So, here is the amazing workaround: Shadow printf so that it actually fprintf() with stdout as argument! Cool, but, Lite-C does not support variadic macros and one of the great things about printf() is that you can put a format string in there and you probably do that and don't want to change your call sites. If you expect some genius solution now, sorry, you are totally out of luck. Here is how to write the basic macro though:

Code:
#define elide_arg (0)
#define pack_args1(arg0) arg0
#define pack_args2(arg0, arg1) arg0, arg1
#define pack_args3(arg0, arg1, arg2) arg0, arg1, arg2

#define printf(format, args) fprintf(stdout, format, args)



And your call sites would need to change like this:

Code:
// Old
printf("Hello World");
printf("Hello %s, %d", "world", 42);

// New
printf("Hello World", elide_arg);
printf("Hello %s, %d", pack_args2("world", 42));



PS: For Chaos, who prefers Haskell over Lite-C, the way to go is using the Text.Printf packaged. Printf has the following signature: printf :: PrintfType r => String -> r
Posted By: alibaba

Re: Acknex.exe with console - 05/06/15 15:29

Thanks for your answers! I read into the topic a bit now.

@Sid
Thank you very much! Unfortunately it seems like Acknex does not support fprintf. It´s also not declared in the windows.h. Or am I on the completely wrong way now?
Posted By: MasterQ32

Re: Acknex.exe with console - 05/06/15 15:34

You can just try to declare the prototype of the function without loading it. Should work as the Lite-C compiler links against the default c runtimes where fprintf is included wink
Posted By: WretchedSid

Re: Acknex.exe with console - 05/06/15 15:42

Pretty sure I have seen stdio.h somewhere before in Lite-C. Try that one.
Posted By: WretchedSid

Re: Acknex.exe with console - 05/06/15 15:45

Actually fuck it, MasterQ32 is the genius. Just resolve printf() from the standard C library and shadow the Gamestudio printf with that one!
Posted By: MasterQ32

Re: Acknex.exe with console - 05/06/15 16:17

Just tried to get a handle to the original printf function, but something doesn't want me to get it running.
I've created a small demo with pure Windows API functions that shows how to write/read from the console:
Code:
#include <acknex.h>
#include <windows.h>
#include <stdio.h>

// We need those headers
BOOL WINAPI WriteConsole(
	HANDLE hConsoleOutput,
	const void *lpBuffer,
	DWORD nNumberOfCharsToWrite,
	DWORD *lpNumberOfCharsWritten,
	void *lpReserved);
	
BOOL WINAPI ReadConsole(
	HANDLE  hConsoleInput,
	void *lpBuffer,
	DWORD  nNumberOfCharsToRead,
	DWORD *lpNumberOfCharsRead,
	void *pInputControl);

function main()
{
	// Create console window
	AllocConsole();
	
	// Get handles to the input and output console
	HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
	HANDLE input = GetStdHandle(STD_INPUT_HANDLE);
	
	// Write some text
	WriteConsole(output, "Hello World!", 12, NULL, NULL);
	
	// Read some text (one line to be exact)
	char buffer[128];
	DWORD len;
	ReadConsole(input, buffer, 127, len, NULL);
	buffer[len] = 0;
	
	// Echo result
	error(buffer);
}

Posted By: alibaba

Re: Acknex.exe with console - 05/06/15 16:39

How cool is that!? Thank you Felix!

And thank you too Sidney! The world of winAPI is really scary, but extremely useful!

BTW Acknex does not want to accept:
Code:
int fprintf (FILE *__stream, const char *__format, ...);

Posted By: MasterQ32

Re: Acknex.exe with console - 05/06/15 16:41

Why is it scary? It's well documented, it's clear, there are plenty of people how know shit.
Just read some stuff here and you'll see what i've done:
https://msdn.microsoft.com/de-de/library/windows/desktop/ms682073(v=vs.85).aspx
Posted By: alibaba

Re: Acknex.exe with console - 05/06/15 16:45

Well I tried it before, but seems like I´ve searched the wrong pages. There were a lot of uncommented stuff, which is why I got lost in first place.
Posted By: Quad

Re: Acknex.exe with console - 05/06/15 17:37

Btw, the exe source was the same one in the sdk_Engine folder, only compiled as console app.

the dll source i posted in first page gives you a cprintf function, which is same as printf, you just declare it in lite-c and init it with PRAGMA_API macro(it's not a plugin dll) then do printf = cprintf; somewhere in your lite-c code. (or init printf itself: #define PRAGMA_API printf;dllname:cprintf, or something like that, not sure if that would work though)

also as far as i can remember physx plugin had bunch of printf's in it and if you use the exe compiled as console app, you see all that in your console, so if your project uses physx alot it renders console virtually unusable. But that was years ago they might have already removed those printfs.

For your use case MasterQ's solution could be more useful though.
© 2024 lite-C Forums