Showing posts with label how to program. Show all posts
Showing posts with label how to program. Show all posts

Tuesday, December 13, 2011

Tutorial - c++ - 2.Hello World!

just checking out the site , looks good , lets actually try and get a gamehacking/cracking forum going , so im doing the most basic C++ program that every begginer learns.

// HELLO WORLD!
#include <iostream>
using namespace std;
int main()
{
// Comment
cout << "Hello World!"<< endl;
system("pause");
return 0;
}

if you run this then you get this window.



now to go throught and explain the code(its so simple)

#include <iostream>

this is a preprocessor statement signified by the '#' , it tells the compiler to "include" the file "iostream". which stands for Input/Output stream , we have to add it to use the "cout" statment.

using namespace std;

this tells the compiler that we are "using" the namespace std, it just makes it easier to use "cout" statements . for example , if we didnt put it in then we would have to use cout like this = std::cout <<"Hello World!"<<endl;

int main()
{ }

now this is out "main" function , all the code inbetween the braces "{ }" is what gets compiled and executed, the "( )" show that main is a function , and the "int" before it just means that it "returns"(ill talk about that later) an integer value.

// Comment

This is how you put comments in your code , the double "//" signify that everything after them (on the same line) is a comment , and the compiler will skip over it.

cout << "Hello World!"<< endl;

Now this is the actual code that outputs our text "Hello World" to the screen. there is also a cin statement , which gets text from the user . so cout and cin(we will use cin later) write and read text to and from the screen. the "<<" just means that the following text is being "cout-ed" , to signify text you have to enclose it in double quotes like this "This is txt". and again the "<<" followed by an "endl" which stands for "ENDLine" and that is what it does , it is like pressing enter when typing , it moves down to the next line.

i probably should have mentioned this in the beggining , but ill do it here , all statements in C++ must end in a semicolon ";" it tells the compiler that the line of code has ended. Also the compiler is the thing that turns your code into code that a computer can understand, its run when you press the ">" run button (in Visual Studio) on your IDE(visual studio and codeblocks are examples of IDE's).enough of that lets move on.

system("pause");

You may not need this , but for me (using vista) if i run the program with out it the console window just flashes and closes , this will "pause" the execution of your program until you press any key(which it says on the console window).

return 0;

this is what your "main()" function returns , which is 0(zero) , this signifies that the program exited/ended normally . without it the compiler would complain.
and like i said before all the code goes between the { },and so our program is done.

i know its not the best looking thing but its a start.

that was pretty indepth if i do say so myself :) , now for people to read it (if there will be any , oh well :D)
 

Tutorial - C++ - 1.DataTypes

ok , im going to go over some of the DataTypes and thier uses here.
the syntax is
datatype variable = value;

"int" which stands for integer, it can hold a number value ranging from -2147483647 to 2147483647

, (if you are using a different compiler then this might vary).
so if i wanted to assign the value 99 to my variable x then i would do the following.


int x;
x = 99;
 here i am declaring that x is an integer , and then later assigning 99 to it

OR

you could do it all in one line.

int x = 99;

next is "char" which stands for character , and it can hold 1 character .

so if i wanted to assign the letter "D" to my char xthen i would do the following .

char x = 'D';

or

char x;
x = 'D'

you have to put single quotes( ' ) around the character you want stored , the letter can be upper or lower case .

just so you know , the letter that ive been using (x) is called an identifier , you can make this whatever you want , so int myinteger = 69; is valid aswell.

next is "float" which stands for "floating point variable" it is like int , but with the exception that it can hold a decimal value , and its range is -1.17549e-38 to 3.40282e+38
but that is just how precise it can be. so you can still assign it a value greater than that , like 999999.9 and it will still work.


float x = 99.4;


next is "double" its pretty much a much more precise float, its rang is -2.22507e-308 to 1.79769e+308 which just like float is its max precision , so assigning the value 9999999999999.999999999 will work .


double x = 89791723467.2374574;


next is "bool" which stands for "Boolean" , this variable can only hold true, or false (or 1=true , 0=false) . bool is mainly used for loops and switches, which will be covered in later tutorials.


bool answr = true;

OR


bool answr = 1;

the two lines mean the same thing , that answr is true

you must assign a data type(int , char , double ect.) to your variable, or else the compiler will give you an error saying that it wasnt defined.

EXAMPLE CODEs

int x = 8;
int y = 2;
int answr = x+y;
cout << answr;


that bit assigns 8 to x and 2 to y ,then x is added with y and their value is stored in the variable answr. So the value of answr is "couted" and its 10.

-----------


int x = 88;
double y = x;
cout <<y;



this bit assigns and int value 88 to x , then assigns the value of x to a double y . then cout's the value of y, which is 88. this is a valid thing to do , but if you tried this


double y = 50.8;
int x = y;
cout << x;


then the value of x would be 50 ,becuase int cannot hold a decimal value , so it is dropped.

-------
char x = 'dvf';
cout << x;


that will output f since char cannot hold more than 1 letter/character , so it is assigned the last character.
but you shouldnt do that anyway , if you wanted to assign a bunch of text/words to a variable you would have to use the string variable (which will be covered in another tutorial)
so remeber char is only for 1 character.

ok that is it for now , ill probably fix up this later , its messy and unfinished

Preview - Cod4 Chams Update 1

Another update , the chams look even better now , they are multicolored(pink and green) and the pink is rendered flat so its easier to see.
here are some screenshots , and i figured why not and make a movie(youtube messed up the great quality and made it choppy for some reason)


nice multi-colored , pink = behind something , and green = visible.

just another sweet picture.


Preview - Cod4 Chams

Mainly just wanted to post this to show off , ill write up a tutorial when im more competent with D3D programming.

but it looks good so far , im using cod4 because when i try to inject into cod6 it crashes(using azorbix's hook so that is probably why, ill write one later)



i got some leaking as you can see here , but this was just a test , ill use numverts and primcount later on.