Console output grabber

I want a module that grabs the whole console output and pushes that into a lua func.

Need any further description? :slight_smile:

I would also like this. Would be useful to me.

Still noone to do this? :l

Possible to hook Msg calls in C++ to Lua?



#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "vfnhook.h"
#include "sigscan.h"

#include <steam/steamclientpublic.h>
#include <interface.h>
#include <netadr.h>
#include <iclient.h>
#include <iserver.h>

#include "common/GMLuaModule.h"

GMOD_MODULE(Load, Unload)

typedef void unknown_ret;

// None of these are used vOv
class CBaseClient;
class CClientFrame;
class CFrameSnapshot;
class bf_write;

CBaseServer* pServer = NULL;
ILuaInterface* gLua = NULL;

DEFVFUNC_(origMsg, bool, (char const* SMsg));
bool VFUNC newMsg(char const* SMsg)
{
	gLua->Push(gLua->GetGlobal("hook")->GetMember("Call"));
		gLua->Push("ConsoleOutput");
		gLua->PushNil(); // Gamemode (Unnecessary, always nil)
		gLua->Push(SMsg);
	gLua->Call(3, 1);

	return origMsg(SMsg);
}

int Load(lua_State* L)
{
	gLua = Lua();

	CSigScan::sigscan_dllfunc = Sys_GetFactory("engine.dll");
	
	if ( !CSigScan::GetDllMemInfo() )
		gLua->Error("CSigScan::GetDllMemInfo failed!");

	CSigScan sigBaseServer;
	sigBaseServer.Init((unsigned char *)
		"\x00\x00\x00\x00\xE8\x2C\xFA\xFF\xFF\x5E"
		"\xC3\x8B\x0D\x00\x00\x00\x00\x51\xB9",
		"????xxxxxxxxx????xx", 10);

	if ( !sigBaseServer.is_set )
		gLua->Error("CBaseServer signature failed!");

	pServer = *(CBaseServer**) sigBaseServer.sig_addr;
	HOOKVFUNC(pServer, 57, origMsg, newMsg);

	return 0;
}

int Unload(lua_State* L)
{
	if ( pServer )
		UNHOOKVFUNC(pServer, 57, origMsg);

	return 0;
}


That only hooks to console output on the server.

I believe Stoned wants it for the client.

This would be very useful, hope someone attempts it.

As Chris said only serverside and I guess that garry will remove con_logfile serverside soon :slight_smile:

I’d like to be able to capture the ‘stats’ output to monitor the CPU usage of the server… Anyone else know of another way? I know about the module that does this but it’s very laggy and I’d like to run it every 5 seconds or so…