[Tutorial] Creating a Basic Hacked Client

Posts 3145 of 46 · Page 3 of 4
Help!!!
Were do u put all the code beginning with "if' in your tutorial? I created a new class named 'Var', added all the '''public static boolean menu = false''' stuff, but now were do I put the rest of the code in ur tutorial!? PLZZ HELP
Quote Originally Posted by SlayaHax View Post
Were do u put all the code beginning with "if' in your tutorial? I created a new class named 'Var', added all the '''public static boolean menu = false''' stuff, but now were do I put the rest of the code in ur tutorial!? PLZZ HELP
Read the OP carefully and it should tell you exactly where to put all the codes.

CheckKeys (In GuiIngame.java)

4. Now once you open GuiIngame
We will add our GUI above
Code:
if (this.recordPlayingUpFor > 0)
        {
            this.mc.mcProfiler.startSection("overlayMessage");
            var33 = (float)this.recordPlayingUpFor - par1;
            blablabla, etc.
            ...
and below:
Code:
   GL11.glPopMatrix();
            this.mc.mcProfiler.endSection();
        }
Hey, LordPankake! Thanks for tutorial, I made my very first client, but I need some help with GUI and hacks. I'm not asking you to give me full codes, just give me some kind of pseudo-code for this stuff:

1. "Enabled hacks" like in Reliant client (really love those) (top-right):

2. A chat-command system, like:
.[hack] [setting]
3. How can I add my hack binds in default "Controls..." menu so users can change them?

Thanks!
P.S. Sorry for bad english, I'm russian
Quote Originally Posted by Prophet12 View Post
*Snip* Requested tuts.
For the GUI like aVo's right-aligned hacks:
Code:
static int color = 0xffffff; //white
FontRenderer fr = mc.fontRenderer; //fr is now short for mc.fontRenderer

int line = 10; 
int line2 = 2;

if(var.ForceOp)
{
     fr.drawStringWithShadow("ForceOp", ScaledResolution.getScaledWidth() - fr.getStringWidth("ForceOp") - 5, line2 + 80, color);line2 += line;
}
if(var.FreeAdmins)
{
     fr.drawStringWithShadow("FreeAdmins", ScaledResolution.getScaledWidth() - fr.getStringWidth("FreeAdmins") - 5, line2 + 80, color);line2 += line;
}
if(var.ForceSpawn)
{
     fr.drawStringWithShadow("ForceSpawn", ScaledResolution.getScaledWidth() - fr.getStringWidth("ForceSpawn") - 5, line2 + 80, color);line2 += line;
}
For the split hacks:
Code:
if(par1Str.startsWith("-Timer"))
    	{
    		
    		try
    		{    			
    			String as0[] = par1Str.split(" ");//So it finds the text after the space. So "-Timer 9001" will be "9001"
    			addChatMessage(as0[1] + "\2472 is now the timer speed");
    			var.Timer = as0[1];
    		}
                catch(Exception e)
                {
                         addChatMessage("\2472 Format incorrect. Use '-Timer SPEED");
                }
    	}
For the keybind changes:
I haven't looked into that. My best advice for now would to be to look into the file that controls that screen. (GuiControls.java)
RE the keybind changes:

Assuming you do it OOP style, what you do is something like:

Base mod class:
Code:
public abstract class mod {
...
public int keybind;
}
And then, in your keybind changer:
Code:
public class KeybindChanger {
...
public void changeKeybind(Key key) {
Mod.keybind = key.getId();
}
}

Something like that.

(Can't really say for sure; haven't gotten mine working yet ^-^)
Quote Originally Posted by godshawk View Post
RE the keybind changes:

Assuming you do it OOP style, what you do is something like:

Base mod class:
Code:
public abstract class mod {
...
public int keybind;
}
And then, in your keybind changer:
Code:
public class KeybindChanger {
...
public void changeKeybind(Key key) {
Mod.keybind = key.getId();
}
}

Something like that.

(Can't really say for sure; haven't gotten mine working yet ^-^)
You could probably use something similar to how minecraft changes its keybinds in vanilla too.
or
Make a chat/console command such as:
"-Bind Fly 33"
It would change Fly's keybind's int to 33. Which is F. Using this setup you could probably achieve the same task. (The key numbers for reference)
Ehh, I just did mine like:

Code:
package com.godshawk.colony.core;

import java****.BufferedReader;
import java****.BufferedWriter;
import java****.File;
import java****.FileInputStream;
import java****.FileNotFoundException;
import java****.FileWriter;
import java********Exception;
import java****.InputStream;
import java****.InputStreamReader;
import java.nio.charset.Charset;

import org.lwjgl.input.Keyboard;

import com.godshawk.colony.mods.Mod;

public class KeyManager {
	
	public File keybindsFile;
	
	public KeyManager( ) {
		keybindsFile = new File( Colony.instance.minecraft.mcDataDir, "/colony/keybinds.colony" );
		if ( !keybindsFile.exists( ) ) {
			try {
				// Create file
				keybindsFile.getParentFile( ).mkdirs( );
				keybindsFile.createNewFile( );
				FileWriter fstream = new FileWriter( keybindsFile );
				BufferedWriter out = new BufferedWriter( fstream );
				// Hardcoded: Just to be sure we get the initial stuff good.
				// This will, ideally, only be used once.
				out.write( "FULLBRIGHT=" + Keyboard.KEY_F + "\r\n" );
				out.write( "TRACER=" + Keyboard.KEY_M + "\r\n" );
				out.write( "AUTOFISH=" + null + "\r\n" );
				out.write( "NUKER=" + Keyboard.KEY_L + "\r\n" );
				out.write( "KILLAURA=" + Keyboard.KEY_P + "\r\n" );
				out.write( "SPRINT=" + Keyboard.KEY_K + "\r\n" );
				out.write( "CHESTESP=" + Keyboard.KEY_C + "\r\n" );
				out.write( "FASTPLACE=" + Keyboard.KEY_N + "\r\n" );
				out.write( "WATERWALK=" + null + "\r\n" );
				out.write( "XRAY=" + Keyboard.KEY_X + "\r\n" );
				out.write( "FLY=" + Keyboard.KEY_J + "\r\n" );
				out.write( "NOFALL=" + Keyboard.KEY_O + "\r\n" );
				out.write( "PLAYERESP=" + Keyboard.KEY_R + "\r\n" );
				
				// Close the output stream
				out.close( );
			} catch ( Exception e ) { // Catch exception if any
				System.err.println( "Error writing keybinds!: " + e.getMessage( ) );
			}
			readKeysAndBind( );
		} else {
			readKeysAndBind( );
		}
	}
	
	public void readKeysAndBind( ) {
		// Initialize variables
		int binding;
		String str = "";
		String name;
		
		InputStream fis = null;
		BufferedReader br;
		String line;
		
		// Try to create FIS
		try {
			fis = new FileInputStream( keybindsFile );
		} catch ( FileNotFoundException e ) {
			// TODO Auto-generated catch block
			e.printStackTrace( );
		}
		// Create BR
		br = new BufferedReader( new InputStreamReader( fis, Charset.forName( "UTF-8" ) ) );
		
		// Don't forget to catch exceptions!
		try {
			while ( ( line = br.readLine( ) ) != null ) {
				// Deal with the line
				// Get the name and keybind number
				str = line.replaceAll( "[^\\d.]", "" );
				name = line.replaceAll( "[\\d.]", "" );
				binding = 0;
				if ( !str.equals( "" ) ) {
					binding = Integer.parseInt( str );
				}
				name = name.replace( "=", "" );
				// Ton of debug stuff gets printed for catching errors
				System.out.println( "binding==" + binding );
				for ( Mod m : Colony.instance.mmanager.mods ) {
					System.out.println( "Attempting to bind: " + m.name );
					System.out.println( "m.name==" + m.name + "|||" + "name==" + name );
					if ( name.equalsIgnoreCase( m.name ) || m.name.equalsIgnoreCase( name ) ) {
						if ( binding != 0 ) {
							m.keyBind = binding;
							System.out.println( "Mod " + m.name + " bound to key ID " + binding + "!" );
							break;
						} else {
							System.err.println( "WARNING: NULL BINDING FOUND!" );
						}
					} else {
						System.err.println( "FAILED TO BIND " + m.name + " AS " + name );
					}
				}
			}
		} catch ( IOException e ) {
			// TODO Auto-generated catch block
			e.printStackTrace( );
		}
	}
	
	public void writeNewKeybinds( ) {
		try {
			FileWriter fstream = new FileWriter( keybindsFile );
			BufferedWriter out = new BufferedWriter( fstream );
			
			// OOPish
			for ( Mod m : Colony.instance.mmanager.mods ) {
				out.write( m.name + "=" + m.keyBind + "\r\n" );
			}
			
			// Close the output stream
			out.close( );
		} catch ( Exception e ) {
			System.err.println( "ERROR WHILE WRITING KEYBINDS: " );
			e.printStackTrace( );
		}
	}
}
And then to change the binds with a command:

Code:
package com.godshawk.colony.console;

import org.lwjgl.input.Keyboard;

import com.godshawk.colony.core.Colony;
import com.godshawk.colony.mods.Mod;
import com.godshawk.colony.util.ChatColour;

public class Bind implements BaseCommand {
	
	private final String name;
	
	public Bind( ) {
		this.name = "bind";
	}
	
 @override
	public void onRun( String[ ] cmd ) {
		// TODO Auto-generated method stub
		try {
			if ( cmd.length == 1 ) {
				throw new NullPointerException( );
			}
			if ( cmd.length == 2 ) {
				Mod m = Colony.mmanager.getHackByName( cmd [ 1 ] );
				m.keyBind = Integer.parseInt( null );
				ConsoleHelper.addMessage( ChatColour.AQUA + m.name + " unbound!" );
			}
			if ( cmd.length == 3 ) {
				Mod m = Colony.mmanager.getHackByName( cmd [ 1 ] );
				m.keyBind = Keyboard.getKeyIndex( cmd [ 2 ].toUpperCase( ) );
				ConsoleHelper.addMessage( ChatColour.AQUA + m.name + " bound to " + cmd [ 2 ] + "!" );
			}
		} catch ( Exception e ) {
			showHelp( );
		}
	}
	
 @override
	public String getName( ) {
		// TODO Auto-generated method stub
		return this.name;
	}
	
 @override
	public void showHelp( ) {
		// TODO Auto-generated method stub
		ConsoleHelper.addMessage( ChatColour.RED + "Usage: " + ChatColour.AQUA + this.getName( ) + " <hack> <key>" );
	}
	
}
And then call writeNewKeybinds() to update the keybinds file.
Quote Originally Posted by godshawk View Post
Ehh, I just did mine like:

Code:
package com.godshawk.colony.core;

import java****.BufferedReader;
import java****.BufferedWriter;
import java****.File;
import java****.FileInputStream;
import java****.FileNotFoundException;
import java****.FileWriter;
import java********Exception;
import java****.InputStream;
import java****.InputStreamReader;
import java.nio.charset.Charset;

import org.lwjgl.input.Keyboard;

import com.godshawk.colony.mods.Mod;

public class KeyManager {
	
	public File keybindsFile;
	
	public KeyManager( ) {
		keybindsFile = new File( Colony.instance.minecraft.mcDataDir, "/colony/keybinds.colony" );
		if ( !keybindsFile.exists( ) ) {
			try {
				// Create file
				keybindsFile.getParentFile( ).mkdirs( );
				keybindsFile.createNewFile( );
				FileWriter fstream = new FileWriter( keybindsFile );
				BufferedWriter out = new BufferedWriter( fstream );
				// Hardcoded: Just to be sure we get the initial stuff good.
				// This will, ideally, only be used once.
				out.write( "FULLBRIGHT=" + Keyboard.KEY_F + "\r\n" );
				out.write( "TRACER=" + Keyboard.KEY_M + "\r\n" );
				out.write( "AUTOFISH=" + null + "\r\n" );
				out.write( "NUKER=" + Keyboard.KEY_L + "\r\n" );
				out.write( "KILLAURA=" + Keyboard.KEY_P + "\r\n" );
				out.write( "SPRINT=" + Keyboard.KEY_K + "\r\n" );
				out.write( "CHESTESP=" + Keyboard.KEY_C + "\r\n" );
				out.write( "FASTPLACE=" + Keyboard.KEY_N + "\r\n" );
				out.write( "WATERWALK=" + null + "\r\n" );
				out.write( "XRAY=" + Keyboard.KEY_X + "\r\n" );
				out.write( "FLY=" + Keyboard.KEY_J + "\r\n" );
				out.write( "NOFALL=" + Keyboard.KEY_O + "\r\n" );
				out.write( "PLAYERESP=" + Keyboard.KEY_R + "\r\n" );
				
				// Close the output stream
				out.close( );
			} catch ( Exception e ) { // Catch exception if any
				System.err.println( "Error writing keybinds!: " + e.getMessage( ) );
			}
			readKeysAndBind( );
		} else {
			readKeysAndBind( );
		}
	}
	
	public void readKeysAndBind( ) {
		// Initialize variables
		int binding;
		String str = "";
		String name;
		
		InputStream fis = null;
		BufferedReader br;
		String line;
		
		// Try to create FIS
		try {
			fis = new FileInputStream( keybindsFile );
		} catch ( FileNotFoundException e ) {
			// TODO Auto-generated catch block
			e.printStackTrace( );
		}
		// Create BR
		br = new BufferedReader( new InputStreamReader( fis, Charset.forName( "UTF-8" ) ) );
		
		// Don't forget to catch exceptions!
		try {
			while ( ( line = br.readLine( ) ) != null ) {
				// Deal with the line
				// Get the name and keybind number
				str = line.replaceAll( "[^\\d.]", "" );
				name = line.replaceAll( "[\\d.]", "" );
				binding = 0;
				if ( !str.equals( "" ) ) {
					binding = Integer.parseInt( str );
				}
				name = name.replace( "=", "" );
				// Ton of debug stuff gets printed for catching errors
				System.out.println( "binding==" + binding );
				for ( Mod m : Colony.instance.mmanager.mods ) {
					System.out.println( "Attempting to bind: " + m.name );
					System.out.println( "m.name==" + m.name + "|||" + "name==" + name );
					if ( name.equalsIgnoreCase( m.name ) || m.name.equalsIgnoreCase( name ) ) {
						if ( binding != 0 ) {
							m.keyBind = binding;
							System.out.println( "Mod " + m.name + " bound to key ID " + binding + "!" );
							break;
						} else {
							System.err.println( "WARNING: NULL BINDING FOUND!" );
						}
					} else {
						System.err.println( "FAILED TO BIND " + m.name + " AS " + name );
					}
				}
			}
		} catch ( IOException e ) {
			// TODO Auto-generated catch block
			e.printStackTrace( );
		}
	}
	
	public void writeNewKeybinds( ) {
		try {
			FileWriter fstream = new FileWriter( keybindsFile );
			BufferedWriter out = new BufferedWriter( fstream );
			
			// OOPish
			for ( Mod m : Colony.instance.mmanager.mods ) {
				out.write( m.name + "=" + m.keyBind + "\r\n" );
			}
			
			// Close the output stream
			out.close( );
		} catch ( Exception e ) {
			System.err.println( "ERROR WHILE WRITING KEYBINDS: " );
			e.printStackTrace( );
		}
	}
}
And then to change the binds with a command:

Code:
package com.godshawk.colony.console;

import org.lwjgl.input.Keyboard;

import com.godshawk.colony.core.Colony;
import com.godshawk.colony.mods.Mod;
import com.godshawk.colony.util.ChatColour;

public class Bind implements BaseCommand {
	
	private final String name;
	
	public Bind( ) {
		this.name = "bind";
	}
	
 @override
	public void onRun( String[ ] cmd ) {
		// TODO Auto-generated method stub
		try {
			if ( cmd.length == 1 ) {
				throw new NullPointerException( );
			}
			if ( cmd.length == 2 ) {
				Mod m = Colony.mmanager.getHackByName( cmd [ 1 ] );
				m.keyBind = Integer.parseInt( null );
				ConsoleHelper.addMessage( ChatColour.AQUA + m.name + " unbound!" );
			}
			if ( cmd.length == 3 ) {
				Mod m = Colony.mmanager.getHackByName( cmd [ 1 ] );
				m.keyBind = Keyboard.getKeyIndex( cmd [ 2 ].toUpperCase( ) );
				ConsoleHelper.addMessage( ChatColour.AQUA + m.name + " bound to " + cmd [ 2 ] + "!" );
			}
		} catch ( Exception e ) {
			showHelp( );
		}
	}
	
 @override
	public String getName( ) {
		// TODO Auto-generated method stub
		return this.name;
	}
	
 @override
	public void showHelp( ) {
		// TODO Auto-generated method stub
		ConsoleHelper.addMessage( ChatColour.RED + "Usage: " + ChatColour.AQUA + this.getName( ) + " <hack> <key>" );
	}
	
}
And then call writeNewKeybinds() to update the keybinds file.
File readers are definetly the way to go. (Also thats a nice setup you have there) although not everyone has a funtional file reader/writer in their coient, although the popular ones usually do.
I'll get around to a tutorial on it after I finish my GUI API (I don't want to have to rely on Darkstorm_'s API; I want to have all my code be MINE lol).

EDIT: Never mind; I'm still too much of an OOP/OpenGL |\|00B to do it xD
Quote Originally Posted by godshawk View Post
I'll get around to a tutorial on it after I finish my GUI API (I don't want to have to rely on Darkstorm_'s API; I want to have all my code be MINE lol).

EDIT: Never mind; I'm still too much of an OOP/OpenGL |\|00B to do it xD
Yeah Im not at that level either, but hey, you can still make a great client without OOP. You'll just get alot of hate for it :P
Yeah, I'll prob. get around to extending my tut and doing a keybinds one soon.
good job! /msg2short
Nice Little Tutorial! Good Work
Will be making a new tutorial which will not edit GuiIngame. This thread was basically meant for early beginners.
Edit: That new tutorial has just been posted.

Quote Originally Posted by hamste View Post
http://www.mpgh.net/forum/417-minecr...st-client.html

Can you help me? Thanks in advance!
sure, I'll edit or post when I find something.

Edit: Red lines are appearing on your Variables.
Is your variables class imported? Is it spelled right?
Posts 3145 of 46 · Page 3 of 4

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?