Jump to content

help with pokemon checksum


Blastoise

Recommended Posts

According to http://projectpokemon.org/wiki/Pokemon_NDS_Structure,the bytes 0x06 & 0x07 are used for the checksum. Along with the footer, pokesav seems to get these bytes wrong. I need someone to give me a more in-depth algorithm for the checksum. This is the one provided on the link:

The checksum is calculated in three steps:

1. Split the unencrypted data from offsets 0x08 to 0x87 into two-byte words,

2. Take the sum of the words, and

3. Truncate the sum to 16 bits.

On step 2, what do you meen by the sum of the words? Is it the sum of the values of the words.

On step 3, I learned from school that truncate means to cut the size of the numbers after the decimal (rounding).

eg. 16.634 truncate 2 = 16.63

Does this version of truncate mean only save the most signifigant digets?

I am planning to make a small program that will take a pokesav *.pkm, and fix it so it is byte-for-byte perfect. Sorry, don't have time to test it myself, and probably won't be able to go back online for a few days. Thanks to anyone who answers :bidoof:

Link to comment
Share on other sites

By the way, if you want GTS fixes the .pkm files if you put a pokemon in deposit and takin'it back off. You'll notice a drastic change in the file, because the file is first erased ( only name/trash bytes/ item hold and happiness are saved) and then re-made following the game directives.

On the other side, people like codemonkey could help you.

Link to comment
Share on other sites

Blastoise, what language are you programming your tool in? I have been writing programs to edit .pkm and .sav files for months now (see my signature), so if you need any help beyond the questions damio has already answered, please let me know.

When I wanted help with checksum in VB.NET you didn't help me :<

Link to comment
Share on other sites

I tried to help you, but it didn't seem like I was explaining it right. It's been months and I even took a VB.Net class (to learn the "proper" way), so I think I would do a better job of it now.

damio, c'mon... you know you're awesome. :D

Anyway, what the heck, here it is:

   ''' <summary>
   ''' Calculate the checksum of the given Pokémon data.
   ''' </summary>
   ''' <param name="PKM">A byte array containing the Pokémon data.</param>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Shared Function Calculate_Checksum(ByVal PKM() As Byte) As UInt16
       Dim Data(PKM.Length - 1)
       For i As Integer = 0 To Data.Length - 1
           Data(i) = PKM(i)
       Next

       Dim index As UInteger = 0

       For i As Integer = &H8 To &H86 Step 2
           index += Data(i) + (Data(i + 1) * 256)
       Next

       Dim bin As String = DecToBin(index, 32)
       bin = bin.Substring(16, 16)
       Return Convert.ToUInt16(bin, 2)

   End Function

   ''' <summary>
   ''' Convert a Decimal number to a binary String.
   ''' </summary>
   ''' <param name="DeciValue"></param>
   ''' <param name="NoOfBits"></param>
   ''' <returns></returns>
   ''' <remarks>Alex Etchells, 2003, http://www.developerfusion.com/code/5430/convert-decimal-integer-values-to-binary-string-in-vb6/</remarks>
   Private Shared Function DecToBin(ByVal DeciValue As Long, Optional _
   ByVal NoOfBits As Integer = 8) As String

       Dim i As Integer
       'make sure there are enough bits to contain the number
       Do While DeciValue > (2 ^ NoOfBits) - 1
           NoOfBits = NoOfBits + 8
       Loop
       DecToBin = vbNullString
       'build the string
       For i = 0 To (NoOfBits - 1)
           DecToBin = CStr((DeciValue And 2 ^ i) / 2 ^ i) & DecToBin
       Next i
   End Function

Link to comment
Share on other sites

so if we just do as you said with GTS our hacked pokes would look 100% legit?

For the others can be legit, for you are fully legal :P, you'll retire a pokemon file with the right

directives. We've seen that some week ago comparing 1 pokesaved pokemon file before and after the GTS, and seeing how the 0x06/0x07 and most important from 0x28 to 0x33 (moves sector) were totally changed. Try and you'll see ;)

Link to comment
Share on other sites

Thanks for that GTS tip. I normally do my programming in c (going to learn fltk for gui's). Which way do I truncate (most signifigant digets first)? Is the checksum made using encrypted, or unencrypted bytes? Thanks to anyone who posts/helps.:grog:

P.S. If you do program in c, how do you find the size of a binary file?

Link to comment
Share on other sites

Which way do I truncate (most signifigant digets first)?

You are going to use the least significant bits. So, if your sum is 0xDC34802F (which is 1101 1100 0011 0100 1000 0000 0010 1111 in binary), then you will truncate it to 0x802F (which is 1000 0000 0010 1111 in binary).

Is the checksum made using encrypted, or unencrypted bytes?

The bytes you use are normally encrypted, but you must decrypt them before you use them to calculate the checksum.

P.S. If you do program in c, how do you find the size of a binary file?

I don't know a lot of C, but I think there is a SizeOf method... in VB.Net, the method exists in the Marshal class.

Link to comment
Share on other sites

Wait a minute. The only thing wrong with .pkm 235-byte from pokesav (byte-by-byte comarison) is the footer and the checksum. The encrypted bytes remain the same. If pokesav got the checksum wrong, how does it encrypt the bytes right? :confused:

The encryption algorithm is using the checksum as a seed for the prng. Then it xor's the prng output with the bytes to be encrypted.

Link to comment
Share on other sites

When you say "footer", what part of the data are you talking about? Also, the size for a party Pokémon should be 236 bytes, not 235.

When a .PKM file is generated, all of the data in that file should be decrypted. And I've never heard of Pokesav incorrectly calculating PKM checksums (not that it would surprise me). Can you post a .PKM file where the checksum was incorrectly calculated so that I may see it?

Link to comment
Share on other sites

Well, according to the wiki, 0xD4-0xEB are seal coordinates, so that's not a footer. There is no footer as far as I know.

In a little while when I have some time, I will run those files through some software of mine. But in the meantime, it looks like the checksum is probably different because the Encounter info is different (the infamous 0x85).

Link to comment
Share on other sites

Hehe. Overlooked 0x85h:eek: So the only difference between legit pokemon & pokesav pokemon is the seal coordinates. If you set the seal coordinates to what my chimchar has (no seals), then there is no way to tell if its legit or not:creep: Thanks everyone =)

Link to comment
Share on other sites

just found out that the trace that we are talking about is only in the "Seal Coordinate"

.. =_=

somehow there are also some traces if you write down the amount of PP left manually

.. but most probably, it can be fixed by redepositing the pokemon in your pokebox

so the remaining one is the seal coordinate ... but i believe that it will also be fixed if it is deposited in the pokebox ...

well .. here is the result of the trace

-- seal coordinate

at hex location 0x0EB(235h)

==> using pokesav, the value is : (0x00)

==> after using GTS trading method, the value is (0x03)

and also there are some fact that ...

GTS will not fix hidden values, fateful encounter, trashbytes, etc etc etc ..

it will only fix the seal coordinate and the amount of PP left =_=

anyway, here is the result (PKM and BIN) for deposited GTS' pokemon and the pokesav's pokemon

http://www.mediafire.com/download.php?ntt0omm42nb

as for the checksum ... it will not change ... as long as you don't write anything in the amount of PP left for each move(in pokesav) , and redeposited the pokemon in the box(in the game) =_=

and also 85h hidden value for pokemon data will be the same whether you use GTS or pokesav, it will not change =_=

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...