I saw a bunch of people who released a "Console" that just used 100 ifs to check if the Command exist. I didn't want to do that so I thought of something else.
First of all we need a ArrayList with the commands and the offset for that command (Seperated by an '=').
[C#]!!
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Vorlage
{
class Program
{
static void Main(string[] args)
{
//------------------------------------------
ArrayList commands = new ArrayList();
commands.Add("title=0x10055BD0");
commands.Add("support=0x10055CAC");
Console.WriteLine("Waiting for Command to execute...\n");
}
Now we have to add something to the code above so we can use our ArrayList in the Method.
Now the actual Method:
Code:
static void Check(ArrayList commands)
{
while (true)
{
What do we need?
-A string (query) that reads the entered command.
-Byte(_byte) to zero out the value before writing to it
-Another string(offset) to grab the offset from the ArrayList(commands)
-A Memory Class (Credits to Jorndel)
So:
Code:
Trainer_Class Proc = new Trainer_Class();
Proc.Process_Handle("iw5mp");
byte[] _byte = new byte[0xFF];
string query = Console.ReadLine();
string offset = null;
How should the user even enter a command?
We expect that the user enters something like:
set <command> <value>
So we need to grab the value from the query to write it to the address later. To do that we first remove the "set ".
set = 3 space = 1. 3+1=4. Obviously. Start Index is 0 ofcourse.
Code:
string value = query.Remove(0, 4); //removes "set " from query
Now it looks like this:
<command> <value>
We have to remove everything before the first Space(' ') now.
Code:
value = value.Substring(value.IndexOf(' ') + 1); //removes <command> from query
So we got the blank value now. Now we have to compare if the entered command(the query) even exist in the ArrayList(commands).
We already know that the query looks like:
set <command> <value>. So something like:
set title drizzle
We also know that the ArrayList entry look like:
title=0x10055BD0
So we can compare the red marked things. We have to remove the "set ", <value> from the query and the =0x10055BD0 from the ArrayList.
First the query:
Code:
string bridge = query.Remove(0, 4); //removes "set " from query
bridge = bridge.Remove(bridge.IndexOf(' ')); //removes <value> from query
Since we got an ArrayList we need an foreach loop.
Code:
bool exist = false;
foreach (string str in commands)
{
if (str.Remove(str.IndexOf('=')) == bridge)
{
offset = str.Substring(str.IndexOf('=') + 1);
exist = true;
break;
}
}
So foreach entry in the ArrayList(commands) it removes the = and the offset from the string(str) to compare it to the bridge(query - "set ", <value>). If they're equal we set the bool exist to true and break the loop. Otherwise it just stays on false.
Now we're almost done. We just need to check now if our bool exist is == true or == false. If it's true it prints out "Command found and Successfully executed." and uses the value we just defined above and the offset to write to the process. If not it prints out "Command not found.". But currently the offset is an string. We need an int for the address. So we need to convert a string hex to an int hex(thanks bio).
Code:
if (exist == true)
{
int i = Convert.ToInt32(offset, 16); //string hex -> int hex
Proc.WriteBytes(i, _byte); //Zero value out first
Proc.WriteString(i, value);
Console.WriteLine("Command found and Successfully executed.");
}
else
{
Console.WriteLine("Command not found.");
}
}
I hope I was able to help you. That kinda was the only thought I had to prevent people from using 1000 if's. The benefit of my method now is that you dont have to add a if statement everytime you add a command. Just add it to the ArrayList e.g:
mycommandname=myoffset
Full Code:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Vorlage
{
class Program
{
static void Main(string[] args)
{
//------------------------------------------
ArrayList commands = new ArrayList();
commands.Add("title=0x10055BD0");
commands.Add("support=0x10055CAC");
Console.WriteLine("Waiting for Command to execute...\n");
Check(commands);
}
/*
* Expected:
* set <command> <value>
*/
static void Check(ArrayList commands)
{
while (true)
{
Trainer_Class Proc = new Trainer_Class();
Proc.Process_Handle("iw5mp");
byte[] _byte = new byte[0xFF];
string query = Console.ReadLine();
string offset = null;
string value = query.Remove(0, 4); //removes "set " from query
value = value.Substring(value.IndexOf(' ') + 1); //removes <command> from query
string bridge = query.Remove(0, 4); //removes "set " from query
bridge = bridge.Remove(bridge.IndexOf(' ')); //removes <value> from query
bool exist = false;
foreach (string str in commands)
{
if (str.Remove(str.IndexOf('=')) == bridge)
{
offset = str.Substring(str.IndexOf('=') + 1);
exist = true;
break;
}
}
if (exist == true)
{
int i = Convert.ToInt32(offset, 16); //string hex -> int hex
Proc.WriteBytes(i, _byte);
Proc.WriteString(i, value);
Console.WriteLine("Command found and Successfully executed.");
}
else
{
Console.WriteLine("Command not found.");
}
}
}
}
}
EDIT:
Move please. Wrong section by accident.