[Mini-Release] Customizing New Console Commands

06/01/2019 18:09 #HB#1
Hey there,

Things were a little boring lately, exams, life... This brings us back to developing hard days.

If you're still interested into developing SRO, yo dude, this thread is for you.

Introduction Video

The goal of the thread won't be that useful for servers as a gameplay, I mean, it will be useful as for staff members only, since they should be the only people who use the console.

What Can I Use This For: Basically, you can do more stuff controlling the server if you have got your own filter or emulator, and you know how to do the communication between the client and the server. But remember to check user's primary & content group before doing the command job, or normal players will play around with media, open console and cheat.


Background Work: Well, searching this could be one of the easiest things you may try to find, the first & correct idea should be in your mind is looking for an existing command name in sro_client strings, and yeah, that's it.

Basically, the client has a list of existing commands, it's loaded on sro_client loading. So, we can hook the function that loads commands and load our custom commands with it, pretty simple. Here's a final output of my code,

Note: I used florian's hooking lib to hook, if you wanna use it, you'll find it in the attachments.

IFConsole.h:
Code:
#pragma once
#include <Windows.h>
#include <iostream>
#include <vector>

typedef bool (CALLBACK ConsoleCommandFunc)(class ConsoleCommandData*);
static std::vector<std::pair<const wchar_t*, ConsoleCommandFunc*>> CustomConsoleCommands;

class ConsoleCommandData
{
public:
	char pad_0000[68]; //0x0000
	const wchar_t* FullCommand; //0x0044
};

class CIFConsole
{
public:
	static void InitializeCustomCommands();
	void OnCommandsLoading();
	void AddCommand(std::wstring commandmaintext, ConsoleCommandFunc* func, int a3);
};
IFConsole.cpp:
Code:
#include "IFConsole.h"
#include "hook.h"
#include "Global.h"

static bool CALLBACK MyCuteTestingFunc(ConsoleCommandData* cmddata)
{
	wchar_t buffer[255];
	swprintf_s(buffer, L"Custom Command Debuggging, Command Entered Text: (%s).", cmddata->FullCommand);
	IngameDebug(buffer);
	return true; // return key success
}

void CIFConsole::InitializeCustomCommands(void)
{
	replaceOffset(0x0055A027, addr_from_this(&CIFConsole::OnCommandsLoading));

	CustomConsoleCommands.push_back(std::pair<const wchar_t*, ConsoleCommandFunc*>(L"HelloWorld", MyCuteTestingFunc));
}

void CIFConsole::OnCommandsLoading(void)
{
	for (auto i = CustomConsoleCommands.begin(); i != CustomConsoleCommands.end(); i++)
	{
		this->AddCommand(i->first, i->second, 0);
	}
	reinterpret_cast<void(__thiscall*)(CIFConsole*)>(0x00558910)(this);
}

void CIFConsole::AddCommand(std::wstring commandmaintext, ConsoleCommandFunc* func, int a3)
{
	reinterpret_cast<void(__thiscall*)(CIFConsole*, std::wstring, ConsoleCommandFunc*, int)>(0x00555DB0)(this, commandmaintext, func, a3);
}
Note: Any addresses given above were found on VSRO 1.88 sro_client, so they are most likely different on any other version.
Note: Structures above are for VC80 libs, back when string/wstring was 28 bytes.
Note: Always compile on Release!

Special thanks to: florian0 :rolleyes:
06/01/2019 23:41 Hercules*#2
Good Work dude
06/02/2019 15:38 XxGhostSpiriTxX#3
good job
01/11/2020 18:55 concucu#4
@[Only registered and activated users can see links. Click Here To Register...]

on VC80 im got errors

Code:
------ Build started: Project: ClientLib, Configuration: Release Win32 ------
  IFConsole.cpp
..\..\..\..\source\libs\ClientLib\src\IFConsole.cpp(83): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
..\..\..\..\source\libs\ClientLib\src\IFConsole.cpp(83): error C2440: 'initializing' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'int'
          with
          [
              _Ty=std::pair<const wchar_t *,ConsoleCommandFunc (__stdcall *)>,
              _Alloc=std::allocator<std::pair<const wchar_t *,ConsoleCommandFunc (__stdcall *)>>
          ]
          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
..\..\..\..\source\libs\ClientLib\src\IFConsole.cpp(83): error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'int' (or there is no acceptable conversion)
          C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK\include\guiddef.h(197): could be 'int operator !=(const GUID &,const GUID &)'
          while trying to match the argument list '(int, std::_Vector_iterator<_Ty,_Alloc>)'
          with
          [
              _Ty=std::pair<const wchar_t *,ConsoleCommandFunc (__stdcall *)>,
              _Alloc=std::allocator<std::pair<const wchar_t *,ConsoleCommandFunc (__stdcall *)>>
          ]
..\..\..\..\source\libs\ClientLib\src\IFConsole.cpp(85): error C2227: left of '->first' must point to class/struct/union/generic type
          type is 'int'
..\..\..\..\source\libs\ClientLib\src\IFConsole.cpp(85): error C2227: left of '->second' must point to class/struct/union/generic type
          type is 'int'
========== Build: 0 succeeded, 1 failed, 10 up-to-date, 0 skipped ==========
Code:
void CIFConsole::OnCommandsLoading(void)
{
	/*for (auto i = CustomConsoleCommands.begin(); i != CustomConsoleCommands.end(); i++)
	{
		this->AddCommand(i->first, i->second, 0);
	}*/ -> this got errors

	reinterpret_cast<void(__thiscall*)(CIFConsole*)>(0x00558910)(this);
}
01/12/2020 00:44 #HB#5
Quote:
Originally Posted by concucu View Post
@[Only registered and activated users can see links. Click Here To Register...]

on VC80 im got errors
Your errors says you didn't include vector, so it doesn't recognize its type.
01/12/2020 03:50 concucu#6
i already include <vector>,
haha i using
Code:
this->AddCommand(L"xxx", MyCuteTestingFunc, 0);
	this->AddCommand(L"xxxx", MyCuteTestingFunc, 0);
	this->AddCommand(L"xxxxx", MyCuteTestingFunc, 0);
	this->AddCommand(L"xxxxxx", MyCuteTestingFunc, 0);
	this->AddCommand(L"xxxxxxx", MyCuteTestingFunc, 0);
01/13/2020 16:43 #HB#7
Quote:
Originally Posted by concucu View Post
i already include <vector>
Well, maybe your VC++ lib is messed then, or your additional includes. I told you what the error indicates anyways.
01/15/2020 00:20 Laag#82#8
good job
01/25/2020 16:00 Empire1453#9
I think it can be used as a new GM ~ notice function
10/06/2020 05:35 halloway520#10
Quote:
Originally Posted by concucu View Post
@[Only registered and activated users can see links. Click Here To Register...]

on VC80 im got errors

Code:
------ Build started: Project: ClientLib, Configuration: Release Win32 ------
  IFConsole.cpp
..\..\..\..\source\libs\ClientLib\src\IFConsole.cpp(83): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
..\..\..\..\source\libs\ClientLib\src\IFConsole.cpp(83): error C2440: 'initializing' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'int'
          with
          [
              _Ty=std::pair<const wchar_t *,ConsoleCommandFunc (__stdcall *)>,
              _Alloc=std::allocator<std::pair<const wchar_t *,ConsoleCommandFunc (__stdcall *)>>
          ]
          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
..\..\..\..\source\libs\ClientLib\src\IFConsole.cpp(83): error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'int' (or there is no acceptable conversion)
          C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK\include\guiddef.h(197): could be 'int operator !=(const GUID &,const GUID &)'
          while trying to match the argument list '(int, std::_Vector_iterator<_Ty,_Alloc>)'
          with
          [
              _Ty=std::pair<const wchar_t *,ConsoleCommandFunc (__stdcall *)>,
              _Alloc=std::allocator<std::pair<const wchar_t *,ConsoleCommandFunc (__stdcall *)>>
          ]
..\..\..\..\source\libs\ClientLib\src\IFConsole.cpp(85): error C2227: left of '->first' must point to class/struct/union/generic type
          type is 'int'
..\..\..\..\source\libs\ClientLib\src\IFConsole.cpp(85): error C2227: left of '->second' must point to class/struct/union/generic type
          type is 'int'
========== Build: 0 succeeded, 1 failed, 10 up-to-date, 0 skipped ==========
Code:
void CIFConsole::OnCommandsLoading(void)
{
	/*for (auto i = CustomConsoleCommands.begin(); i != CustomConsoleCommands.end(); i++)
	{
		this->AddCommand(i->first, i->second, 0);
	}*/ -> this got errors

	reinterpret_cast<void(__thiscall*)(CIFConsole*)>(0x00558910)(this);
}

for (std::vector<std::pair<const wchar_t*, ConsoleCommandFunc*>>::iterator i = CustomConsoleCommands.begin(); i != CustomConsoleCommands.end(); i++)
{
this->AddCommand(i->first, i->second, 0);
}
reinterpret_cast<void(__thiscall*)(CIFConsole*)>(0 x00558910)(this);