You are viewing our Forum Archives. To view or take place in current topics click here.
#131. Posted:
PoloMehBro
  • TTG Senior
Status: Offline
Joined: Nov 19, 201113Year Member
Posts: 1,363
Reputation Power: 58
Status: Offline
Joined: Nov 19, 201113Year Member
Posts: 1,363
Reputation Power: 58
CoNdEmR wrote This thread contains several tutorials from several thread's from various websites i do not take credit for all of this work.

Since thetechgame started getting huge as it is to this day, there have been many leech's, noob's or whatever you want to call them, asking stupid question making stupid topics and threads for many questions that may seem very obvious to some.

Well i want to see that stopped. 90% of the posts in this section are to do with MW2 codes's patch's and the likes. What im going to do here is help educate the not so educated into becoming a rather good modder. So let's get started.


The following tut is all thanks to K Brizzle and is a tut on the most basic programming that goes in the patch_mp.ff file. The file is written in the C++ programming language.

Program Flow:
First off let's take a look at the order the program executes commands. Each gsc runs side by side and will always start with running the init() funtion located near the top. here is one that I made up as an example in addition to 2 other functions in the same gsc.

init()
{
        self.variable = 100;
        self thread doCommands();
        self goHere();
}

doCommands()
{
        //commands
}

goHere()
{
        //commands
}


Alright so the program starts by running the init() function. First it will execute the "self.variable = 100;" line. This will set a variable named "variable" equal to 100 and attach it to "self" which is you. Next it moves to the next line "self thread doCommands();". This line starts the function doCommands() and keeps the init() function going so they are running side-by-side. Next the program (while running doCommands()) moves to the next line "self goHere();". Notice that this line does not have the thread command in the middle. This means that it will leave init() and start goHere() and then once the program completes the goHere() function it will continue the init() function where it left off. Now after going through the init() function we have set self.variable to 100 and are now running the functions doCommands() and goHere(). Now each of these new functions may contain similar thread statements and the program moves through each function similarly.

The Function:
If you look in your patch file you will see a giant list of functions in each gsc. The general form of a function look like this:
function(argument1,argument2,argument3...)
{
        //commands go here
}


Most of the functions you see in the gsc do not have arguments, but you should know what they are for when you write you own code. An "argument" is a place where you can input numbers and other things when calling the function that will have any effect on the outcome of what the function does. for example:

init()
{
self thread iniNuke(1,12,20,5);
}

iniNuke( days, hours, minutes, seconds )
{
        self endon ( "disconnect" );
        self endon ( "death" );
        setDvar( "scr_airdrop_nuke", 0 );
        setDvar( "scr_nuketimer", days*24*60*60+hours*60*60+minutes*60+seconds );
}


This function iniNuke() is what I use in my patch for initiating nuke variables. You see that the function is called in init(). and has 4 arguments days,hours,minutes, and seconds. The days is 1, the hours is 12, the minutes is 20, and the seconds is 5. Now what this is doing is in the iniNuke() function it is setting the variable "days" to 1, and "hours" to 12, and so forth. Then, later in the function, the variables can be used. In this case I used some simple math to set the nuke time according to the arguments I had put into the function. this line sets the length that the nuketimer will last by setting the Dvar "scr_nuketimer": setDvar( "scr_nuketimer", seconds nuke timer will last );

self endon ( "disconnect" );
        self endon ( "death" );


Now this part of the function is what tells the function when to stop. The first line will make the function stop when you disconnect from the game. The second line will end the function when you die. Most functions will need the first line. Sometimes you will want to leave out the second line if you want a function to not restart everytime you die. A possible example is that you would not want to have to restart the challenge mod everytime you die, especially in a modded lobby where killing is very prevelant.

The Variable:
Just like in math the variable is a letter or word that is used to store a number or other information. In this example we are storing some information in to these variables.

self.coolnessLevel = 100;
level.modded = 1;
functionName = "Modded Lobby";


In this example first we set the variable self.coolnessLevel to 100. The "self." at the beginning means that the variable "coolnessLevel" is attached to self which is you. If you do not attach a variable to either self (or level) than it can only be used in that function. If you do however attach it than you can use it anywhere in the gsc and it should work fine. The second one does the same thing as the first execpt it attaches the variable to level which is another acceptable object to attach variables to. The last line sets a normal variable as a "string". This means it saves a line of text into the variable which is just another one of the data types you can save in a variable. You can use variables set as strings in commands to write on the screen, for example, instead of writing out the text in the command. Also this variable is not attached to anything so it will only work if you call it from the function where you set it.

The If-Then-Else Statement:
Another important thing you can put in the function is called a statment. Statements use logic to do things. One such statemeent if the If-then-else statment modeled here:
if (self.name=="Fireflex is GOD") {
                        self thread iniHost();
                } else {
            self thread maps\mp\gametypes\_hud_message::hintMessage( "Welcome to K Brizzle's Lobby" );
                }


What this does is it compares self.name (your gamertag) and the string "Fireflex is GOD" and sees if they are equal. Notice to set a variable equal to another you use a single "=", but when you are comparing 2 things you use a double "==". The If statement checks if the statement 'self.name=="Fireflex is GOD"' is true. If it is, then it will do what is contained within the {} brackets after it. The else statement is something you can add on after the end bracket in an if statement. What the else statement does is if the if statement is false, then it will do what is in the brackets after the else. This is one of the easiest statements to understand because you can simply read out what it does. If (this is true) {do this} else {do this other thing}.

The "==" can be interchanged with other logic statements as follows:
== //equal to
> //greater than
< //less than
!= //not equal to


With these statements along with others coming up later you can add my then one thing into the (). By using "and" (&&) or "or" (||) you can have multiple things inside the same if. Here is an example:
if (self.name=="Fireflex is GOD" || self.name=="CoreTony" || self.name=="I K Brizzle I") {
                        self thread iniHost();
                } else {
            self thread maps\mp\gametypes\_hud_message::hintMessage( "Welcome to K Brizzle's Lobby" );
                }


So what this says is if (this=this or this=this or this=this) then {do this}. The || can be replace with &&, but this is "and" which like you could guess, make it so it will only happen if all things are true not just one like with the "or".

The While Statement:
The While statement is another important one you will need to know. Here is an example from the Rain Money code.
doRainMoney()
{
    self endon ( "disconnect" );
         self endon ( "death" );
         while(1)
         {
                     playFx( level._effect["money"], self getTagOrigin( "j_spine4" ) );
                     wait 0.5;
         }
}


The while statement is like saying while (this is true) {do this}. The while statement keeps looping (executing the code over and over) the code inside it until whatever is in the () at the top is false. In this example we put simply put a "1" in the (). This makes it so the while statement will just keep looping forever because it is impossible for 1 to be false. False=0 True=1. Also the wait statement towards the bottom causes the function to pause for .05 seconds. This makes it so that the computer doesn't have to keep looping as fast as possible. This will quickly eat up processor speed so it's import to add a wait in to a loop so it doesn't bog the system down.

Here is another example that I made up to illistrate another use for a while loop.
doWhile()
{
    self endon ( "disconnect" );
    self endon ( "death" );
        self thread waitA();
        self.waitForButton = 0;
    while(self.waitForButton==0)
    {
                wait 0.05;
    }
        self iPrintlnBold( "You pressed the A button!" );
}

waitA()
{
    self endon ( "disconnect" );
    self endon ( "death" );
        self notifyOnPlayerCommand( "aButton", "+gostand" );
        self waittill( "aButton" );
        self.waitForButton = 1;
}

This code first starts in the dowhile() function and then from there starts waitA() along side of it. Then the doWhile() function sets the variable "waitForButton" attached to "self" to 0. The function then goes into the while statement and keeps waiting for .05 seconds until it sees that self.waitForButton is not equal to 0. Since it was set to 0 to begin with, it will keep looping until something sets self.waitForButton to something other than 0. That's where the waitA() function comes in. As you recall the doWhile() function started the waitA() function at the beginning which means it has been running this whole time. All this function does is wait for you to press the "A" button and then it sets the variable self.waitForButton to 1. So there you go this is your outside force changing the variable. Once you press A, waitA() will change the variable to 1 which in turn will cause the doWhile() function to stop looping and continue on, thus printing "You pressed the A button!" on the screen.



Next is a tut by deep3r on how to modify the default.xex.
How To Decompile An XEX in IDA!

Requirements:

XEX Loaders (Xorloser)
IDA 5.2+
XEX File
XEX Tool



XEX modding does take some practice and isn't easy but with a bit of time and research you'll get it done. You'll need to look at it and Learn as much as you can about PPC there is also an Auto-Comment feature in IDA which helps out in looking at mnemonics.

STEP One

First open CMD and follow the directory in which you XEX and XEX Tool is in.
Now you'll need to type the following into CMD make sure your XEX file is default.xex if you're going to copy and paste my example.


xextool -b default.exe -i default.idc default.xex



STEP Two

Now leave CMD open as the Load address is important when coming to IDA.

Now what you'll need to do is open IDA and open the default.exe file you just created it should be in the same folder as you XEX file. Once you've opened this and it's on a setup kind of screen. Now you'll need to click on Binary. Once you've click on binary change the processor type to PowePc: PPC and click ok and click yes.

STEP Three


Now you're on a screen with Addresses, now in CMD the address if you opened Halo 3 .xex is 0x82000000 you type this into two boxes "Rom start address" and "Loading Address" and now click ok.

Now click file, open and click IDC file and open the default.idc you just created and now it'll ask you would you like to analyze, click yes.

Once this is completed you've successfully opened you XEX into IDA.

Now you'll also need a good idea of PowerPC assembly language to understand how everything works in the XEX without knowing PPC this is almost impossible so I've posted some really nice link to some great tutorials.


Very good basics tutorial:
[ Register or Signin to view external links. ]



Harder:
[ Register or Signin to view external links. ]



Makes the harder tutorial Easier to understand:
[ Register or Signin to view external links. ]




The Default.xex is written in machine code which is hard to understand and modify but if you take the time to read the very good tutorial's on them you should be modifying your default.xex in no time.

The main thing i'd advise you to learn first and foremost is C++:
What is C++?:

C++ (pronounced "See plus plus") is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features. Read more...

What is C++ used for?
For big software projects that require high performances. Most major applications and games are made in C++.
Examples: Photoshop, Firefox, Winamp, Counter Strike...

Short list of C++ compilers:
For Windows:
Borland C++ 5.5
Microsoft Visual C++ Express
DevCPP
For Linux:
G++(contained in GCC which comes preinstalled in most distros)
Intel C++ (free for noncommercial use only)
For Mac OS X:
Apple C++
Xcode
GCC

The following is a list of good and free tutorials on learning C+= that i myself found very useful.

C++ Video tutorials:
http://www.youtube.com/antirtfm
http://www.youtube.com/user/reconnetworks


This is only the most basic start to get you on the way to bettering yourself at modding and coding which is rather essential in this business. And i take no credit for the first two tutorials i did not write them


A very helpful post indeed. I shall keep this in mind for when I start Hosting
#132. Posted:
BKRxRaNDomV3
  • Resident Elite
Status: Offline
Joined: May 26, 201113Year Member
Posts: 231
Reputation Power: 8
Status: Offline
Joined: May 26, 201113Year Member
Posts: 231
Reputation Power: 8
thank you very much for this helpful topic!!
+ rep was given
#133. Posted:
dalegibb
  • Christmas!
Status: Offline
Joined: Mar 01, 201212Year Member
Posts: 88
Reputation Power: 3
Status: Offline
Joined: Mar 01, 201212Year Member
Posts: 88
Reputation Power: 3
thanks alot but its like trying to learn german lol, i suppose ill always be a leach
#134. Posted:
Icp
  • TTG Senior
Status: Offline
Joined: Jul 20, 201113Year Member
Posts: 1,109
Reputation Power: 24
Status: Offline
Joined: Jul 20, 201113Year Member
Posts: 1,109
Reputation Power: 24
Very very useful post, thank you
#135. Posted:
FudgeYouAll
  • Rising Star
Status: Offline
Joined: May 08, 201212Year Member
Posts: 707
Reputation Power: 29
Status: Offline
Joined: May 08, 201212Year Member
Posts: 707
Reputation Power: 29
This Needs To Be Sticky! Ill Vouch For It!
#136. Posted:
matwleader
  • Challenger
Status: Offline
Joined: Jun 10, 201212Year Member
Posts: 140
Reputation Power: 5
Status: Offline
Joined: Jun 10, 201212Year Member
Posts: 140
Reputation Power: 5
My god lots of writing
#137. Posted:
matwleader
  • Challenger
Status: Offline
Joined: Jun 10, 201212Year Member
Posts: 140
Reputation Power: 5
Status: Offline
Joined: Jun 10, 201212Year Member
Posts: 140
Reputation Power: 5
This will stop the leechers lol
#138. Posted:
fwiz
  • Powerhouse
Status: Offline
Joined: Jan 20, 201212Year Member
Posts: 484
Reputation Power: 17
Status: Offline
Joined: Jan 20, 201212Year Member
Posts: 484
Reputation Power: 17
good steps to stop leaches lol
#139. Posted:
-Tier-
  • Powerhouse
Status: Offline
Joined: Apr 22, 201014Year Member
Posts: 498
Reputation Power: 21
Status: Offline
Joined: Apr 22, 201014Year Member
Posts: 498
Reputation Power: 21
CoNdEmR wrote thread's leech's noob's


Not to troll a staff member who's probably going to abuse and give me a bogus warning, but you cant just throw apostrophes on anything you want. Threads, leeches, and noobs will do just fine. It honestly bothers me when people can't figure out fourth grade grammar.

OG-Gamertag wrote
A very helpful post indeed. I shall keep this in mind for when I start Hosting

Quoting the whole thread... now that's classy.
#140. Posted:
MP4
  • Video King
Status: Offline
Joined: Feb 20, 201014Year Member
Posts: 1,700
Reputation Power: 142
Status: Offline
Joined: Feb 20, 201014Year Member
Posts: 1,700
Reputation Power: 142
Very good post dude, good job!
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.