[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)
As you guys can now see, adding values to a string isn't that hard
It's done like this:
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:
The program shown above would return the string:
Incerementing the string is possible:
The above program would output:
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:
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:
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 ^^
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();
}
It's done like this:
Code:
template<typename T>string append(const T& stuff) {
stringstream output;
oss << stuff;
return output.str();
}
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;
}
Hi 1337
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;
}
Hi 1337
Hi 1338
Hi 1338
And see this:
Code:
PushToconsole(const char* command)
No worrys just shove it into that function like this:
Code:
PushToconsole(str.c_str())
Ok that's it, thanks for reading this I hope it helps
-SCHiM
ps: Me is going on a vacation ^^



