Hello everyone,
I have received numerous PMs asking how I made my loader, in which you can choose the hack options. I thought it would be easier to make a tutorial than reply to everyones PMs.
This is what my loader looks like: (click the picture to go to the hack download thread)
So, the idea is for the loader to create a file in the Cross Fire folder which has all the options in it. Then, the hack reads this file, and enables/disables the corresponding hacks.
In my loader, it created a file that looked like this:
Code:
This file is automatically generated by AlphaHack configurator. Do not edit!
1
0
0
1
1
0
1
0
1
0
1
1
1
-1
1 is for ON and 0 is for OFF.
The hack reads that file, line by line, and sets the hack up. The hack and the loader both know that line 0 is for No Change Delay, and line 1 is for No Reload etc etc etc.
Very simple... very very simple indeed.
If you don't know how to read and write to files in C++, keep reading, or if you do go and try to do it. (or you could do it in VB.NET)
First, we need to include two headers to read and write to files:
Code:
#include <windows.h>
#include <fstream>
#include <iostream>
Then, to write the options file, first we have to make a new ofstream (output file stream), and create a file with open()
Code:
ofstream file;
file.open("FileName");
Then, before we try to write data to the stream, we need to check if the file was successfully created, then we write data to the stream using the << operator.
Code:
if(file.good())
{
file << "Data To Write To File";
}
Then we need to close the file stream:
I will leave it to you to make it loop around and write the correct amount of lines with the correct values... should be very easy.
Now that we know how to create the file, we need to make the hack read from it.
First we include the headers
Code:
#include <windows.h>
#include <fstream>
#include <iostream>
Then we need to create an ifstream (input file stream) and open the file:
Code:
ifstream file;
file.open("FileName");
Before we try to read data from it we need to check if it has successfully opened the file:
Then we need to read a line with getline, and covert it to an integer with atoi()
Code:
int option = -1;
string line;
std::getline(file, line);
option = atoi(line.c_str());
Now we need to loop while the line is either 0 or 1 (at the end of file it is -1, so it will stop there), set the correct bool to the correct value, get the next line, and increment the counter by 1:
note: the counter is the line number
Code:
while((option == 1) || (option == 0))
{
if(option == 0)
{
switch(counter)
{
case 0:
nochange = false;
break;
case 1:
noreload = false;
break;
case 2:
seeghosts = false;
break;
case 3:
weaponhack = false;
break;
case 4:
noweaponweight = false;
break;
case 5:
nonadedamage = false;
break;
case 6:
nofalldamage = false;
break;
}
}
std::getline(file, line);
option = atoi(line.c_str());
counter++;
}
NOTE: You may want to add some try catches in case of an error...
Code:
try
{
//CODE
//error happens
throw 1;
}
catch(int e)
{
string errornumber = "";
string str = "Error ";
itoa(e, errornumber, 10);
str.append(errornumber);
MessageBoxA(NULL, str, "Hack", MB_OK | MB_ICONERROR);
}
NOTE: In my hack, i set all the bool values to true, and only change them if the corresponding value in file is 0 (simpler)
Full Code for writing to file:
Code:
#include <windows.h>
#include <fstream>
#include <iostream>
ofstream file;
file.open("FileName");
if(file.good())
{
if(noreload)
file << "1\n";
else
file << "0\n";
}
file.close()
Full Code for reading file:
Code:
#include <windows.h>
#include <fstream>
#include <iostream>
ifstream file;
file.open("FileName");
if(file.good())
{
int option = -1;
string line;
std::getline(file, line);
option = atoi(line.c_str());
while((option == 1) || (option == 0))
{
if(option == 0)
{
switch(counter)
{
case 0:
nochange = false;
break;
case 1:
noreload = false;
break;
case 2:
seeghosts = false;
break;
case 3:
weaponhack = false;
break;
case 4:
noweaponweight = false;
break;
case 5:
nonadedamage = false;
break;
case 6:
nofalldamage = false;
break;
}
}
std::getline(file, line);
option = atoi(line.c_str());
counter++;
}
}
So, that's it!
Please thanks me/give credits if you use this.
Btw, I nearly lost all this, LUCKY IT HAS AUTO-SAVE
If you are having trouble with this, use common sense lol.