porting animations from one skeleton to another?

EDIT:
solution: Blender 2.6 comes with an animation retargetting addon.

orig post:

I made a really messy thread about this by not telling my actual problem in hopes of simplifying it for people who are willing to help, but ending up making things even more confusing. So I’m trying again, this time with the exact issue and example images to make things clearer.

I need to share animations (actions) between Armatures which have EditBones with same names and which have the same positions, but can have different angles and scales. Plus the Armatures might have different bone hierarchy (bone parenting/ no bone parenting).

Why I need to do this:

I’ve made an importer/exporter for a 3d format for a game. The format doesn’t store enough info to connect/parent the bones, which makes posing/animating character models nearly impossible. As there are only 2 character skeleton types in the game, I decided to optionally allow to generate the bone from a hardcoded data in the importer and undo that in the exporter. This allows to easily pose the model for checking weights, makes it easier for Blender to generate automatic weights and of course makes animating possible.

Here is the difference between having the Armature generated from the files or by the script, from harcoded data:
http://i50.tinypic.com/2fx40cx.jpg

Now this worked perfectly: the importer optionally generated the Armature itself and the exporter removed those changes, so the exported model worked with existing animations in the game.
But now I’m writing an importer and exporter for the game’s animation format and here come the problems of:

  1. Trying to make animations work in Blender with my “custom” (modified) Armature,
  2. Trying to make animations created by using the custom Armature work with the original models in the game (and Blender).

Some conversion is needed, but I’m not sure what as I’m not a professional programmer. Plus maybe I don’t need Python scripting to be able to do this.

Here’s what will happen now if I’ll try to import an animation in Blender on the “custom” Armature:
http://i47.tinypic.com/213gbc7.jpg

Someone suggested for the exporter to have a dublicate Armature which would have the bone transforms from the original and use constraints to get the “real” position/location/scale" each frame, but constraints/bone snapping wouldn’t work because this is how they work:

http://i48.tinypic.com/281r8mg.jpg

imagine the bone head geometry attached:
http://i49.tinypic.com/352p6xs.jpg

I’m not sure, maybe this would be better off in the “Python support” section of the forum, but on the other hand Animators might know how this can be done with the GUI, which can later be automated by scripts.

With Python, it seems I just need to get the “difference” between the EditBone matrices of all EditBones for the two Armatures somehow and apply that difference to PoseBone matrices of all PoseBones. I need to know how to get that difference and how to apply it.