[TUT] Using templates in ptc hacks

Posts 1–9 of 9 · Page 1 of 1
[TUT] Using templates in ptc hacks
Ok, so in response to cristyboys counter tut, I'll show you guys how you can easily increment values inside a string, this can come in handy anytime making a hack eg: to create ghost mode

That reminds me, I wrote this tutorial because I saw so many people trying to append integers to a string the other day, so that's why

Reg:

Knowlegde of C++ (or any other language that supports templates or external code)
Template knowlegde (easy as shit)

Headers and namespaces:
#include <iostream>
#include <windows.h>
#include <string>
#include <sstream>
using namespace std;

I'll document the code for u guys to understand

First well create a function template to add numeric values to our class to help you understand about templates

(A template is a blueprint for the compiler/linker to create other instances of a functions from, T stands for the type that is to be replaced when a specific instance of a function is created)

Here's how a normal template function would look like (this is a verry easy example that increments any given numeric value (bool, float, int, double, dword, word)

Code:
#include <windows.h>
#include <iostream>

template<typename T>T inc(const T a){ // T could be replaced with any other char, but just like you put 'p' infront of a pointer you'd put T in a Template
return a + 1;
}

int main{
int i = 10;
		cout<< i <<endl;
		i = inc(i);   //Here a new instance of function inc will be created for type int
		cout<< i <<endl;
		cin.ignore();
}
As you guys can now see, adding values to a string isn't that hard
It's done like this:


Code:
template<typename T>string append(const T& stuff) {
	    stringstream output;
	    oss << stuff;
	    return output.str();
	}
This template creates a string stream (wich doesn't care about it's variables being integers/chars or whateverfucktardedvariable)

And then shoves our T value (which can be anything realy)
Into our string stream, it then returns the string so calling it like this:

Code:
#include <iostream>
#include <windows.h>
#include <string>
#include <sstream> 
using namespace std;

int main(){
string str = "Hi "; // create an std::string
int l33t = 1337;  // our integer (remember any variable will do)

str = append(l33t);  // create a new instance of our std::string append function to shove the integers (in this case with the name stuff) into our string stream and return it to the main string, be sure to use the += operator or else your string wil be: 1337, and not Hi 1337)
cout<<str<<endl;
cin.ignore;
}
The program shown above would return the string:
Hi 1337
Incerementing the string is possible:

Code:
int main(){
string str = "Hi ";
int l33t = 1337;

str += append(l33t);
cout<<str<<endl;
l33t++;
str = "Hi ";
str += append(l33t);
cout<<str<<endl;
cin.ignore;
}
The above program would output:

Hi 1337
Hi 1338
Now those of you with less programming experience but with the potention to become really good will look at their base (probably gellins or whatever)

And see this:

Code:
PushToconsole(const char* command)
And then they think: 'Ohh F*ck', because the ub3r ultr4 c00l dud3 in the tutorial used a std::string, I can't use this, what to do??

No worrys just shove it into that function like this:

Code:
PushToconsole(str.c_str())
Adding .c_str() will make the string almost like a const char* so this'll work like a charm

Ok that's it, thanks for reading this I hope it helps

-SCHiM

ps: Me is going on a vacation ^^
good tutorial mate
Nice job, hope this helps out the users on here
Or just do it this way:


Code:
#include <sstream>
int value = 50;
void main()
{
	std::stringstream s;
	s << "Command " << value << ".000000";
	PushToConsole(s.str().c_str());
	s.str("");
}
Quote Originally Posted by Killahr View Post
Or just do it this way:


Code:
#include <sstream>
int value = 50;
void main()
{
	std::stringstream s;
	s << "Command " << value << ".000000";
	PushToConsole(s.str().c_str());
	s.str("");
}

Ye but your function doesnt look as Nice as mine

is in a train to France ATM!!!!
Quote Originally Posted by schim View Post
Ye but your function doesnt look as Nice as mine

is in a train to France ATM!!!!
all i have to typ is this:

double value1 = 1;
PushToConsole("ShowFPS",value1);

or

PushToConsole("ShowFPS",1);

you 2 are still looping arround it... i dont >

+ u still need to press a space after each command why not add this afer command << " " or + " "
Quote Originally Posted by Kuro Tenshi View Post

all i have to typ is this:

double value1 = 1;
PushToConsole("ShowFPS",value1);

or

PushToConsole("ShowFPS",1);

you 2 are still looping arround it... i dont >

+ u still need to press a space after each command why not add this afer command << " " or + " "


Maybe C# just takes care of shoving integers into strings, couse C++ doesn't it fucks around with you till you get mad, cause by default all strings in C++ that are defined like this: "string", are constant

Now normaly you would be able to cast it away, but not when using asm fucntions (strcpy, memcpy, strcat)
Could use <const cast>value

but that's just boring

And template knowledge is an usefull knowledge to have, so I thought about writing a'lil tutorial about it

@zoom
Thank you, expect more to be coming this way as I keep learning more and more

-SCHiM
Great to see some new tutorials, good job.
Posts 1–9 of 9 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?