By
_GHOSTER_
Wrote this, maybe someone can find a use for it. Allows you to declare cvars, and users to toggle them.
ie: user types NameESP 1 - This will set the value 'bound' to nameesp to 1.
ie: user types Chams 4 - Sets chams value to 4.
The point of this is just so you can have the differ values do different things, ie: chams 1-9 are different colors.
So here is CConsole.h
Code:
#include <Windows.h>
#include <stdio.h>
#include <vector>
using namespace std;
#define Clear(x) strcpy(x, "")
struct ConsoleVars
{
char *szToggleText;
int *BindValue;
};
struct BindingVars
{
int Chams, NameESP;
};
class CConsole
{
public:
CConsole()
{
ScrollUp = 1;
}
void InitConsole();
void HandleKeyPress(int iVirtualKey);
void OnEnter(char *szPassedText);
void RenderText(int iX, int iY, char *szText, DWORD dwColor);
void RenderInput(int iX, int iY, int iStart);
void AddItem(char *szText);
void PredictiveText(char *szBeingTyped);
void AddConsoleVar(char *szToggleText = "", int *Bind = 0);
BindingVars Cheats;
private:
char ReadChar[256];
char Final[256];
char InfoBuffer[256];
int ScrollUp;
std::vector<std::string> Input;
std::vector<ConsoleVars> Cvars;
};
And here is CConsole.cpp
Code:
#include "cConsole.h"
//Add any console init code here, I showed how to add cvars, and a welcome message.
void CConsole::InitConsole()
{
this->AddConsoleVar("Chams");
this->AddConsoleVar("NameESP", &Cheats.NameESP); //Case sensitve, easy fix though...if you care
AddItem("Welcome to GHOSTER console, v1");
}
//Just push an item onto our vector
void CConsole::AddItem(char *szText)
{
this->Input.push_back(szText);
}
//Predictive text, to predict old commads.
void CConsole::PredictiveText(char *szBeingTyped)
{
//Have fun!
}
//This is what is called when enter is pressed.
void CConsole::OnEnter(char* szPassedText)
{
int ConsoleVarValue = 0;
this->Input.push_back(szPassedText);
for(int iVar = 0; iVar < (int)this->Cvars.size(); iVar++)
{
if(strstr(szPassedText, this->Cvars[iVar].szToggleText)) //If it contains our cvar
{
sprintf(this->InfoBuffer, "%s", szPassedText);
for(int i = 0; i < (int)strlen(szPassedText); i++)
{
if(tolower((int)InfoBuffer[i]) >= 0x30 && tolower((int)InfoBuffer[i]) <= 0x5A) //If its a number
ConsoleVarValue = InfoBuffer[i] - '0'; //Convert to number
}
if(this->Cvars[iVar].BindValue)
sprintf(this->InfoBuffer, "Variable: %s, has been toggled to: %i", this->Cvars[iVar].szToggleText, ConsoleVarValue);
else
sprintf(this->InfoBuffer, "No value bound to: %s", this->Cvars[iVar].szToggleText);
AddItem(this->InfoBuffer);
Clear(InfoBuffer);
if(this->Cvars[iVar].BindValue)
*this->Cvars[iVar].BindValue = ConsoleVarValue; //Set to our parsed number, if no number its 0
}
}
Clear(this->Final); //Clear infobuffer
}
void CConsole::HandleKeyPress(int iVirtualKey)
{
bool bShiftDown = ((GetKeyState(VK_SHIFT)&0xFF00) != 0); //is shift down
if(iVirtualKey == VK_BACK)
this->Final[(strlen(this->Final) - 1)] = '\0';
else if(iVirtualKey == VK_SPACE)
strcat(this->Final, " ");
else if(iVirtualKey == VK_RETURN)
this->OnEnter(this->Final);
else if(iVirtualKey == VK_UP)
{
if(ScrollUp <= (int)this->Input.size())
{
strcpy(Final, this->Input[ (this->Input.size() - ScrollUp ) ].c_str());
ScrollUp++;
}
}
if(iVirtualKey >= 0x30 && iVirtualKey <= 0x5A)
{
char keyPress = (char)iVirtualKey;
if(!bShiftDown)
sprintf(this->ReadChar, "%c", (char)tolower((int)keyPress), iVirtualKey);
else
sprintf(this->ReadChar, "%c", (char)keyPress);
strcat(this->Final, this->ReadChar);
}
}
//Aligns text left.
void CConsole::RenderText(int iX, int iY, char *szText, DWORD dwColor)
{
void *vGameText = (void*)0x4F6CX0;
__asm
{
PUSH 1
PUSH dwColor
PUSH [szText]
PUSH iY
PUSH iX
PUSH 0x95BXBC
CALL [vGameText]
ADD ESP, 0x18
}
}
//Render the input, and past input.
void CConsole::RenderInput(int iX, int iY, int iStart)
{
this->RenderText(500, 500, this->Final, 0xffff00ff); //This is what they are typing, print this in your edit box
for(int iBegin = 0; iBegin < (int)this->Input.size(); iBegin++)
{
RenderText(iX, iY + ( iBegin * 0x14 ), (char*)this->Input[iBegin].c_str(), 0xFFFFFFFF);
}
}
//creates and pushes a cvar onto stack
void CConsole::AddConsoleVar(char *szToggleText, int *Bind)
{
ConsoleVars pVar;
pVar.szToggleText = szToggleText;
pVar.BindValue = Bind;
this->Cvars.push_back(pVar);
}
Enjoy or Don't. Should be easy to understand and follow, any questions post.
Probably not as good as it could be but oh well