|
-
October 1st, 2010, 02:13 PM
#5
Re: Problem with args
Code:
using System;
using System.IO;
using System.Globalization;
namespace pokeshift
{
class Program
{
static void Main(string[] args)
{
UInt32 PID = 0x00, Letter = 0x00, ReadLetter = 0x00, Pokeball = 0x00, Checksum = 0x00;
String OTName = "", PKMName = "", ReadLine = "", OutputPath = "";
MemoryStream ms = new MemoryStream(136);
StreamReader sr = new StreamReader("Table.tbl");
Console.WriteLine("Pokeshift v0.01 by Kazo - Research by kaphotics\n");
if (args.Length > 0)
{
//shifts each file
for (int i = 0; i < args.Length; i++)
{
FileStream fs = File.OpenRead(Convert.ToString(args[i]));
BinaryReader br = new BinaryReader(fs);
ms = new MemoryStream(136);
br.BaseStream.Position = 0x00;
ms.Position = 0x00;
//Copies file in to memory.
for (int j = 0; j < 136; j++)
{
ms.WriteByte(br.ReadByte());
}
br.Close();
//Removes item.
ms.Position = 0x0A;
ms.WriteByte(0x00);
ms.WriteByte(0x00);
//Sets Nature.
ms.Position = 0x00;
PID = Convert.ToUInt32(ms.ReadByte()) + (Convert.ToUInt32(ms.ReadByte()) * 0x100) + (Convert.ToUInt32(ms.ReadByte()) * 0x10000) + (Convert.ToUInt32(ms.ReadByte()) * 0x1000000);
ms.Position = 0x41;
ms.WriteByte(Convert.ToByte(PID % 25));
//Removes Pt/HGSS locations.
ms.Position = 0x44;
ms.WriteByte(0x00);
ms.WriteByte(0x00);
ms.WriteByte(0x00);
ms.WriteByte(0x00);
//Name conversion.
ms.Position = 0x48;
PKMName = "";
for (int j = 0; j < 10; j++)
{
ReadLetter = 0xFFFF;
Letter = Convert.ToUInt32(ms.ReadByte()) + (Convert.ToUInt32(ms.ReadByte()) * 0x100);
if (Letter != 0xFFFF)
{
sr = new StreamReader("Table.tbl");
while (Letter != ReadLetter)
{
ReadLine = sr.ReadLine();
ReadLetter = UInt32.Parse(ReadLine.Substring(0, 4), NumberStyles.AllowHexSpecifier);
}
PKMName += ReadLine[5];
sr.Close();
}
else
{
j = 10;
}
}
ms.Position = 0x48;
for (int j = 0; j < PKMName.Length; j++)
{
ms.WriteByte(Convert.ToByte((Convert.ToUInt32(PKMName[j])) - ((Convert.ToUInt32(PKMName[j]) / 0x100) * 0x100)));
ms.WriteByte(Convert.ToByte(Convert.ToUInt32(PKMName[j]) / 0x100));
}
//OTName conversion.
ms.Position = 0x68;
OTName = "";
for (int j = 0; j < 7; j++)
{
ReadLetter = 0x00;
Letter = Convert.ToUInt32(ms.ReadByte()) + (Convert.ToUInt32(ms.ReadByte()) * 0x100);
if (Letter != 0xFFFF)
{
sr = new StreamReader("Table.tbl");
while (Letter != ReadLetter)
{
ReadLine = sr.ReadLine();
ReadLetter = UInt32.Parse(ReadLine.Substring(0, 4), NumberStyles.AllowHexSpecifier);
}
OTName += ReadLine[5];
sr.Close();
}
else
{
j = 10;
}
}
ms.Position = 0x68;
for (int j = 0; j < OTName.Length; j++)
{
ms.WriteByte(Convert.ToByte((Convert.ToUInt32(OTName[j])) - ((Convert.ToUInt32(OTName[j]) / 0x100) * 0x100)));
ms.WriteByte(Convert.ToByte(Convert.ToUInt32(OTName[j]) / 0x100));
}
//Met location.
ms.Position = 0x80;
ms.WriteByte(0x31);
ms.WriteByte(0x75);
//Pokeball.
ms.Position = 0x86;
Pokeball = Convert.ToUInt32(ms.ReadByte());
if (Pokeball != 0x00)
{
ms.Position = 0x86;
ms.WriteByte(0x00);
ms.Position = 0x83;
ms.WriteByte(Convert.ToByte(Pokeball));
}
//Removes Pokethlon stats.
ms.Position = 0x87;
ms.WriteByte(0x00);
//Updates checksum.
ms.Position = 0x08;
Checksum = 0;
for (int j = 0; j < 64; j++)
{
Checksum += Convert.ToUInt32(ms.ReadByte()) + (Convert.ToUInt32(ms.ReadByte()) * 0x100);
Checksum = (Checksum - ((Checksum / 0x10000) * 0x10000));
}
ms.Position = 0x06;
ms.WriteByte(Convert.ToByte((Checksum) - ((Checksum / 0x100) * 0x100)));
ms.WriteByte(Convert.ToByte(Checksum / 0x100));
//Saves new file.
Console.WriteLine(PKMName + " was shifted.");
OutputPath = args[i].Substring(0, args[i].Length - 4) + "_Shifted.pkm";
ms.Position = 0x00;
File.WriteAllBytes(OutputPath, ms.ToArray());
}
}
else
{
Console.WriteLine("Please drag a .pkm file on to the exe.");
Console.ReadLine();
}
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|