Blastoise Posted May 26, 2009 Posted May 26, 2009 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:
Gold88 Posted May 26, 2009 Posted May 26, 2009 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.
Hippyx420x Posted May 27, 2009 Posted May 27, 2009 so if we just do as you said with GTS our hacked pokes would look 100% legit?
damio Posted May 27, 2009 Posted May 27, 2009 The sum of the words means to add them. Truncate, when using the hexadecimal number system (at least), means to cut off all unnecessary bytes, eg. 0xFFFFFF truncated to 2 bytes is 0xFFFF
codemonkey85 Posted May 27, 2009 Posted May 27, 2009 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.
damio Posted May 27, 2009 Posted May 27, 2009 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 :<
codemonkey85 Posted May 27, 2009 Posted May 27, 2009 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. 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
Gold88 Posted May 27, 2009 Posted May 27, 2009 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 , 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
Blastoise Posted May 27, 2009 Author Posted May 27, 2009 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?
codemonkey85 Posted May 27, 2009 Posted May 27, 2009 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.
Blastoise Posted May 29, 2009 Author Posted May 29, 2009 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.
codemonkey85 Posted May 30, 2009 Posted May 30, 2009 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?
Jiggy-Ninja Posted May 30, 2009 Posted May 30, 2009 He might mean the extra bytes that are tacked onto Party Pokemon.
Blastoise Posted May 30, 2009 Author Posted May 30, 2009 Footer = last part of the file, opposite of the header (seems to be static). Ok, it makes much more sence if the .pkm file is decrypted. Compare the two attached files chimchar.pkm is the real one, and chimcharf.plm is the pokesav one. Forgot that my hex editor starts at 0x00, whoops:O) Thanks for helping. chimchar.pkm chimcharf.pkm
codemonkey85 Posted May 30, 2009 Posted May 30, 2009 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).
Blastoise Posted June 1, 2009 Author Posted June 1, 2009 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 =)
xeomyr Posted June 2, 2009 Posted June 2, 2009 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 =_=
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now