Pk2 Tools (Source)

08/15/2012 20:38 Th3K1nG#1
Hello,
Is there any simple C# source, to extract a single file from the Media.pk2 and add this again?

For Example what i mean with "simple" i found this to Read: pk2Reader.dll

PHP Code:
//Usage Example

            
pk2.pk2Reader reader = new pk2Reader(@"Path to Media.pk2");
            
byte[] chardata reader.getFile("characterdata_5000.txt");
            
TextReader txtReader = new StreamReader(new MemoryStream(chardata));
            
Console.WriteLine(txtReader.ReadLine());
            
Console.Read(); 
08/15/2012 22:59 lesderid#2
If you have that DLL, pk2Reader.dll, you can use it by referencing it in your C# project.

If you're interested in the source code, you could decompile it with Reflector or dotPeek, unless the IL is obfuscated, which might make it a bit harder...
08/15/2012 23:44 Nezekan#3
There is a lot of info about it in drew's releases, you might want to check them out. It is really not that hard
08/16/2012 01:17 theonly112#4
Quote:
Originally Posted by Th3K1nG View Post
For Example what i mean with "simple" i found this to Read: pk2Reader.dll

PHP Code:
//Usage Example

            
pk2.pk2Reader reader = new pk2Reader(@"Path to Media.pk2");
            
byte[] chardata reader.getFile("characterdata_5000.txt");
            
TextReader txtReader = new StreamReader(new MemoryStream(chardata));
            
Console.WriteLine(txtReader.ReadLine());
            
Console.Read(); 
You found [Only registered and activated users can see links. Click Here To Register...]

Heres the source: [Only registered and activated users can see links. Click Here To Register...]

It's horrible code, but it works.
08/16/2012 01:40 fatihy93#5
Quote:
Originally Posted by theonly112 View Post
You found [Only registered and activated users can see links. Click Here To Register...]

Heres the source: [Only registered and activated users can see links. Click Here To Register...]

It's horrible code, but it works.
How can i read SV.T ?
08/16/2012 03:07 DaxterSoul#6
Code:
        public static int Decrypt(byte[] buffer)
        {
            Pk2.Blowfish bf = new Pk2.Blowfish(Encoding.ASCII.GetBytes("SILKROADVERSION"), 0, 8);
            Array.Reverse(buffer, 4, 4);
            Array.Reverse(buffer, 8, 4);
            bf.Decrypt(buffer, 4, buffer, 4, 8);
            Array.Reverse(buffer, 4, 4);
            Array.Reverse(buffer, 8, 4);

            int version;
            int.TryParse(Encoding.ASCII.GetString(buffer, 4, 4), out version);

            return version;
        }
Another PK2Reader: [Only registered and activated users can see links. Click Here To Register...]
Blowfish for that: [Only registered and activated users can see links. Click Here To Register...]
08/16/2012 14:19 illstar#7
@DaxterSoul the pk2reader you posted is broken

sPK2Entry
Position = 8byte (PosHigh << 32 | PosLow or just read int64 instead )
nextChain = 8byte not 4
08/16/2012 15:26 DaxterSoul#8
Works fine for me :P
By the way it was your original vb.net code translated to C# ^^
08/16/2012 15:59 lesderid#9
Quote:
Originally Posted by DaxterSoul View Post
(...)
Another PK2Reader: [Only registered and activated users can see links. Click Here To Register...]
(...)
+1 for using IDisposable.
08/16/2012 16:10 ÑõÑ_Ŝŧóp#10
Quote:
Originally Posted by lesderid View Post
+1 for using IDisposable.
welcome back,my friend
y u no skype?
08/16/2012 16:55 lesderid#11
Quote:
Originally Posted by ÑõÑ_Ŝŧóp View Post
welcome back,my friend
y u no skype?
I don't really use Skype, I do use MSN though.
08/16/2012 19:40 Nezekan#12
Quote:
Originally Posted by ÑõÑ_Ŝŧóp View Post
welcome back,my friend
y u no skype?
was he gone?
08/17/2012 19:24 Th3K1nG#13
Quote:
Originally Posted by theonly112 View Post
You found [Only registered and activated users can see links. Click Here To Register...]

Heres the source: [Only registered and activated users can see links. Click Here To Register...]

It's horrible code, but it works.
thanks for share

Quote:
Originally Posted by DaxterSoul View Post
Code:
        public static int Decrypt(byte[] buffer)
        {
            Pk2.Blowfish bf = new Pk2.Blowfish(Encoding.ASCII.GetBytes("SILKROADVERSION"), 0, 8);
            Array.Reverse(buffer, 4, 4);
            Array.Reverse(buffer, 8, 4);
            bf.Decrypt(buffer, 4, buffer, 4, 8);
            Array.Reverse(buffer, 4, 4);
            Array.Reverse(buffer, 8, 4);

            int version;
            int.TryParse(Encoding.ASCII.GetString(buffer, 4, 4), out version);

            return version;
        }
Another PK2Reader: [Only registered and activated users can see links. Click Here To Register...]
Blowfish for that: [Only registered and activated users can see links. Click Here To Register...]
also thanks for share...


at least too much pastebin... but ill give a try ;)

EDIT: But this is ONLY for reading isn't it? how about edit, and import into the pk2?
08/17/2012 23:02 DaxterSoul#14
I worked on it but can't find it anymore. But if you break down the Code and read some threads you'll be able to write it on your own.
03/26/2020 01:45 cardoso125874#15
how about edit, and import into the pk2?