Many thanks, Moriarty! I can't say it works perfectly, as I'm getting weird critical exceptions, but it's a big progress.
Now let's make some stuff.

EDIT
Now I have another question - sorry if it's silly, but it's my first time modding X-Com. I'm making a custom minigun for fun now and it works fine... However, the palette is broken in Ufopedia while in the battlescape inventory picture it is not.
Battlescape pic (correct):

Ufopedia pic (broken):

Seeing as it's the same picture that is used in both places, I don't know why this happens. Help, please?