Jump to content

Black/White


Pedro250

Recommended Posts

Hi again,

In the Project Wikia there is a method of Checksum calculation, but don't know what language is it wrote, maybe someone can help me converting it to .net language? Thanks

The link is http://www.projectpokemon.org/wiki/Pok%C3%A9mon_NDS_Save_File_Checksum

It looks like C or C++. It might be similar enough to C#, but I'm not sure...

Edited by evandixon
typo
Link to comment
Share on other sites

I'm not 100% sure, but I believe the checksum calculation for Black & White is different than the Gen IV games. So I don't think that page is going to help...

At any rate, here is the code I've been using for DPPt & HGSS:

       Private Function GetSeeds() As Integer
           seeds = New Integer(&H100 - 1) {}

           Dim v0 As Integer = 0
           Dim v1 As Integer
           Dim v2 As Integer
           Dim result As Integer

           Do
               v1 = v0 << 8
               v2 = 0
               Do
                   If (CType(v1 >> 8, [byte]) And &H80) <> 0 Then
                       v1 = (2 * v1) Xor &H1021
                   Else
                       v1 *= 2
                   End If
                   v2 += 1
               Loop While v2 < 8
               result = CUShort(v1)
               seeds(v0) = result
               v0 += 1
           Loop While v0 <= &HFF
           Return result
       End Function

       Public Sub FixBlockChecksum(ByVal Block As mDPGeneralBlock)
           Block.Footer.Checksum = SaveBlockChecksums(Block)
       End Sub

       Public Sub FixBlockChecksum(ByVal Block As mDPStorageBlock)
           Block.Footer.Checksum = SaveBlockChecksums(Block)
       End Sub

       Public Sub FixBlockChecksum(ByVal Block As mDPHallOfFameBlock)
           Block.Footer.mChecksum = SaveBlockChecksums(Block)
       End Sub

       Private Function SaveBlockChecksums(ByVal Block As mDPGeneralBlock) As UShort
           GetSeeds()
           Dim Data() As Byte = RawSerialize(Block)
           Dim v2 As Integer = &HFFFF
           Dim i As Integer
           Dim v4 As Integer = Block.Footer.Size - &H14
           Dim v6 As Byte

           i = 0
           Do While v4 > 0
               v4 -= 1
               v6 = CType(Data(i) Xor CType(v2 >> 8, [byte]), [byte])
               v2 = (v2 << 8) Xor seeds(v6)
               i += 1
           Loop
           Return CUShort(v2)
       End Function

       Private Function SaveBlockChecksums(ByVal Block As mDPStorageBlock) As UShort
           GetSeeds()
           Dim Data() As Byte = RawSerialize(Block)
           Dim v2 As Integer = &HFFFF
           Dim i As Integer
           Dim v4 As Integer = Block.Footer.Size - &H14
           Dim v6 As Byte

           i = 0
           Do While v4 > 0
               v4 -= 1
               v6 = CType(Data(i) Xor CType(v2 >> 8, [byte]), [byte])
               v2 = (v2 << 8) Xor seeds(v6)
               i += 1
           Loop
           Return CUShort(v2)
       End Function

       Private Function SaveBlockChecksums(ByVal Block As mDPHallOfFameBlock) As UShort
           GetSeeds()
           Dim Data() As Byte = RawSerialize(Block)
           Dim v2 As Integer = &HFFFF
           Dim i As Integer
           Dim v4 As Integer = Block.Footer.Size - &H18
           Dim v6 As Byte

           i = 0
           Do While v4 > 0
               v4 -= 1
               v6 = CType(Data(i) Xor CType(v2 >> 8, [byte]), [byte])
               v2 = (v2 << 8) Xor seeds(v6)
               i += 1
           Loop
           Return CUShort(v2)
       End Function

FYI, RawSerialize just turns a data structure into a byte array. I'm not sure how you're working with your data, but I'm guessing you're already using it as a byte array.

Link to comment
Share on other sites

I'm not 100% sure, but I believe the checksum calculation for Black & White is different than the Gen IV games. So I don't think that page is going to help...

At any rate, here is the code I've been using for DPPt & HGSS:

       Private Function GetSeeds() As Integer
           seeds = New Integer(&H100 - 1) {}

           Dim v0 As Integer = 0
           Dim v1 As Integer
           Dim v2 As Integer
           Dim result As Integer

           Do
               v1 = v0 << 8
               v2 = 0
               Do
                   If (CType(v1 >> 8, [byte]) And &H80) <> 0 Then
                       v1 = (2 * v1) Xor &H1021
                   Else
                       v1 *= 2
                   End If
                   v2 += 1
               Loop While v2 < 8
               result = CUShort(v1)
               seeds(v0) = result
               v0 += 1
           Loop While v0 <= &HFF
           Return result
       End Function

       Public Sub FixBlockChecksum(ByVal Block As mDPGeneralBlock)
           Block.Footer.Checksum = SaveBlockChecksums(Block)
       End Sub

       Public Sub FixBlockChecksum(ByVal Block As mDPStorageBlock)
           Block.Footer.Checksum = SaveBlockChecksums(Block)
       End Sub

       Public Sub FixBlockChecksum(ByVal Block As mDPHallOfFameBlock)
           Block.Footer.mChecksum = SaveBlockChecksums(Block)
       End Sub

       Private Function SaveBlockChecksums(ByVal Block As mDPGeneralBlock) As UShort
           GetSeeds()
           Dim Data() As Byte = RawSerialize(Block)
           Dim v2 As Integer = &HFFFF
           Dim i As Integer
           Dim v4 As Integer = Block.Footer.Size - &H14
           Dim v6 As Byte

           i = 0
           Do While v4 > 0
               v4 -= 1
               v6 = CType(Data(i) Xor CType(v2 >> 8, [byte]), [byte])
               v2 = (v2 << 8) Xor seeds(v6)
               i += 1
           Loop
           Return CUShort(v2)
       End Function

       Private Function SaveBlockChecksums(ByVal Block As mDPStorageBlock) As UShort
           GetSeeds()
           Dim Data() As Byte = RawSerialize(Block)
           Dim v2 As Integer = &HFFFF
           Dim i As Integer
           Dim v4 As Integer = Block.Footer.Size - &H14
           Dim v6 As Byte

           i = 0
           Do While v4 > 0
               v4 -= 1
               v6 = CType(Data(i) Xor CType(v2 >> 8, [byte]), [byte])
               v2 = (v2 << 8) Xor seeds(v6)
               i += 1
           Loop
           Return CUShort(v2)
       End Function

       Private Function SaveBlockChecksums(ByVal Block As mDPHallOfFameBlock) As UShort
           GetSeeds()
           Dim Data() As Byte = RawSerialize(Block)
           Dim v2 As Integer = &HFFFF
           Dim i As Integer
           Dim v4 As Integer = Block.Footer.Size - &H18
           Dim v6 As Byte

           i = 0
           Do While v4 > 0
               v4 -= 1
               v6 = CType(Data(i) Xor CType(v2 >> 8, [byte]), [byte])
               v2 = (v2 << 8) Xor seeds(v6)
               i += 1
           Loop
           Return CUShort(v2)
       End Function

FYI, RawSerialize just turns a data structure into a byte array. I'm not sure how you're working with your data, but I'm guessing you're already using it as a byte array.

Thanks a lote, i will check on this.

I am hex editing the data, but i am thinking in change the data management , hex editing brings a lot of problems, so it's ok.

Thanks again

Link to comment
Share on other sites

Instead of asking for someone else to do the work for you, why don't you try to understand it yourself and ask questions specific to what you don't understand? If you don't understand ANY of it, you probably shouldn't be trying to do it anyway.

Codr, not trying to start a fight or anything but i made both 4º gen and 5º gen evolution editor (along with allot more non-pokemon related programs), i know how to do this things

I am more directed to ROM editing, not SAVE editing OK? Everyone starts some way, you start your way, i star mine.

If you don't want to help, don't criticize, if you want to help, just help.

Thanks

Link to comment
Share on other sites

if you want to help, just help.

How does someone do that without doing all the work for you? You're not giving someone a starting point. You're not asking questions. You just want it done, which is equivalent to begging.

Since you obviously misinterpreted my last post, let me make it clear that the post wasn't made in an attempt to elicit negative emotions from you.

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...