Thank you, I've looked at it, but I don't know visual basic (in fact, I know very little programming).
I've taken advantage of MPKR making a backup of the savefile to compare what happens when I withdraw a pokemon and deposit a different one. The result was that the only changes to the file are the ones shown in the following image (and obviously the 136 bytes correponding to the pokemon I deposited, which now take the place of the one I withdrawed):
EDIT: I also tried to just enter the ranch and save 2 times in a row, then extract the savedata. The only difference between the two savedata were the bytes marked in red in the image (0x00-0x19 and 0x63).
I also tried withdrawing the first pokemon deposited at the ranch, then depositing a different one, which shifts the whole pokemon data 164 bytes. But same result. Removing a pokemon has the same changes to the header (well, the pokemon start offset is updated, as stated below).
The checksum is definitely one of those, maybe 0x60-0x63 is the header checksum and 0x00-0x19 is the savedata header.
Also, I noticed some values in the header are offsets in the file:
- Underlined in the image, they seem to be just some index values
- In a black square I've marked the values of the offsets of different sections in the savegame:
0x00-0x19: SHA-1 hash of all the following data in the file
0x24-0x27: start offset of mii data entries in the ranch
0x2C-0x2F: start offset of "mii-trainer" data entries in the ranch
0x34-0x37: start offset of pokemon data
0x3C-0x3F: ending offset of pokemon data (after this the savegame is all 0x00)
[ATTACH=CONFIG]11917[/ATTACH]
UPDATE: found it! 0x00-0x19 is a SHA-1 checksum of the rest of the savedata. 0x60-0x63 might be a time value, since in subsecuent savefiles it only increases.
Thankully this is a very common checksum, so I will be able to update the id changer app myself!
UPDATE_2: I successfully edited my pokemon ranch savefile and could download all pokemon to a different diamond/pearl savegame, without modifying the nds savegame.
It required some extra tweaking, like adding TID, SID, Name to one of the mii-trainer entries (this one was expected). I need more testing, because in my successful attemp i just changed all the trainer data existing in the savefile (which only had had one trainer ever) to the new one and I don't know if changing them all is required, as my save had 3 consecutive TID, SID, Name for no apparent reason. Maybe it is a log of the last trainers that connected to the ranch for the ranch and wiiconnect features?
I'll do more testing tomorrow, but the big part is done.
UPDATE_3: The process is now automatic. I updated the id-changer and coded a program that updates the hash. I coded it as a separate application because that way one can manually modify the savefile, for example, to change a pokemon for other, and add event pokemon to the ranch for example.
With the information in this thread one could write a full save editor, that changes the trainers in the ranch and the pokemon they have stored. It would be nice for people who don't have access to AR or nds flashcarts to mingle with pearl/diamond savegames, but I'm not going to code it, and since my pokemon ranch is only for diamond/pearl I doubt anyone will take that much interest as to code it.
I'll update first post with new binaries and the info I've gathered later.
UPDATE_4: First post updated. I doubt I will work on this anymore, source and all the information I gathered is available in the rar attached to the first post.
UPDATE_5: updated first post with new information and a tool to change the savegame region/language setting