EDIT: HT (Handler Trainer) data (name + gender) is currently written with the Pokémon data.
But now, I fear about the memories, the previous regions and everything related with the HT when not OT... How should it work? AND How should we do? (since it can differ)
Woops, forgot about that, will check right away.
I don't fully understand your worries though. As long as I see in the pokemon structure, the only thing that changes with trades is last trainer's Name and gender. Well, gonna see what the bank does.
EDIT: I see, there's a whole block of data about not OT.
EDIT2:
@Gocario, seems like memories are set as if the pokemon was traded. Gonna test a little more, but pkhex does not handle this either.
Probably the game autogenerates those memory data when withdrawing from box and a last OT / current OT divergence is found...
I would need a different region savegame (EUR) to test how the region data is updated too, because I have 2 saves from 2 different cartridges, but region data is the same, so that remains unchanged.
It's nothing that can't be achieved, I'll run some more tests to see if the memories are randomly generated; if they are we can replicate it even if not the exact randomizing is done.
EDIT3: there's something I won't be able to test, which is the following situation:
1.- Get pokemon A from game 1 to PHB
2.- Transfer pokemon A to game 2 (diferent region)
3.- Trade pokemon a from game 2 to game 3 (a third region), without withdrawing from boxes
4.- Check if regional memories from game 2 where conserved.
EDIT 4: went to the memory recaller, the pokemon is treated as if it were still under original trainer's care.
Pokemon Bank to cartridge transfer really seems to work just like a trade, friendship is also set to its vase value:
http://bulbapedia.bulbagarden.net/wiki/List_of_Pokémon_by_base_friendship
In my previous edit I said I wanted to check what happened to geolocation, but I think they are simply moved one slot down and the location of the current save is put as latest location (geolocation 0) even if it is the same geolocation. I can test that, but would take quite some transfers.
I'll see what happens when the pokemon returns to original trainer and if the memories are actually randomly generated for each pokemon.
Memory type and area are always the same for pokemon Bank (bulbapedia states that ORAS only locations are changed to somewhere, but a X pokemon transfered to an Y game was changed to somewhere).
I need to check if affection, fullness and enjoyment are set to 0 with the transfer ( I guess so).
If intensity and feeling are randomly generated, we can mimic what pokemon bank does.
EDIT5:
I need to test more, but feeling seems random, intensity seems to be set to lowest value, affection, fullness and enjoyment seem to be set to 0. I've also checked with normally traded pokemon trough GTS and this seems to be how memory values are handled.
On the other hand, when a pokemon returns to its original trainer, two things happen (need to hex check, but I have to go now):
1.- Current Handler is set to OT, no other data is touched
2.- Friendship with original trainer is restored, instead of returning to base value.