View Full Version : Esemjay's KFM Converter


esemjay
Feb 12, 2008, 11:19 PM
Overview

This is a simple tool, done in C# (Sorry C++ Buffs, C# was faster), to convert KFM files to XML format for quick editing. It doesn't do much that you can't do with your favorite HEX editor, but hopefully it'll allow a few people to add animations to their models.

I wasn't able to do what I wanted with it, but this was more a part of my modeling experience than it is of the tool. The animations spliced well with the model; but I was having trouble getting the "extra" items (parachute) to show up. It ended up looking like a paradrop with an invisible parachute.

Readme
Disassembling your KFM file
Disassembling a KFM file is as simple as clicking your mouse.


Step 1: Open KFM Utility
http://img149.imageshack.us/img149/1640/step1gx9.th.jpg (http://img149.imageshack.us/my.php?image=step1gx9.jpg)

Step 2: Click "Open" for the KFM Field.
http://img158.imageshack.us/img158/187/step2rp8.th.jpg (http://img158.imageshack.us/my.php?image=step2rp8.jpg)

Step 3: Find and open the KFM file you wish to edit. This file must exist to decode.
http://img206.imageshack.us/img206/3393/step3ux0.th.jpg (http://img206.imageshack.us/my.php?image=step3ux0.jpg)

Step 4: Find and open the XML file you wish to save to using the same method as the KFM file. This file does not have to exist to decode.
http://img521.imageshack.us/img521/2137/step4xn4.th.jpg (http://img521.imageshack.us/my.php?image=step4xn4.jpg)

Step 5: Press the "Decode" button to convert from KFM to XML.
http://img201.imageshack.us/img201/3733/step6ao3.th.jpg (http://img201.imageshack.us/my.php?image=step6ao3.jpg)

The XML file should now be in the directory you selected, with the filename you chose.

Warning - Part of the save process involves overwriting the existing file. Always work on a copy.


To reassemble the KFM file from the XML file, follow the same steps as above, but press "Encode" instead of "Decode." This will convert the XML file you chose into the KFM file you chose.

XML Syntax
There are two XML files that this utility will use; one of which is the XML file you Encode/Decode with, and the other comes with the executable, named "AnimCodes.xml".

Since the average user won't need to know anything other than "Do not delete this file", I will discuss the syntax in the Decompiled KFM file first.

KFM

<KFM>
<Header /> <!-- STRING -->
<!-- Doesn't seem important, but is still decoded. -->

<NIF /> <!-- STRING -->
<!-- Name of the NIF file that these animations apply to. -->

<Master /> <!-- STRING -->
<!-- Almost always "MD". This is the master node for the NIF file. -->

<Unknown /><!-- INTEGER -->
<!-- I have no clue what this does. Nobody seems to. Seriously. -->
<!-- It's just... like... there. But it's decoded anyways. -->

<Animations>

<!-- Begin Repeat -->
<Animation>
<Event /><!-- [INTEGER/STRING] -->
<!-- If it is a String, don't worry about it. It corresponds to a value -->
<!-- defined in AnimCodes.xml -->

<!-- If it is an Integer, that means that it is Undefined in AnimCodes.xml -->
<!-- but will still encode properly. -->

<Variation /><!-- INTEGER -->
<!-- This Value seems to be important; in "Vanilla" models, it seems to -->
<!-- always be "0", while in BtS models, it seems to usually be a multiple -->
<!-- of "5". If you copy-paste data, this number seems to be important. -->

<File /><!--String -->
<!-- This points to the .KF (Animation) file to run when this animation is -->
<!-- called. On your first decode, this should be self-explanatory. -->

</Animation>
<!-- End Repeat -->
<!-- That section will repeat for every animation file present in the KFM. -->

</Animations>
</KFM>


As with all XML, tags are CaSe SeNsItIvE.

AnimCodes

<AnimCodes version="0.1">
<!-- The Version String means nothing. It's just to help you keep track of -->
<!-- updated versions of this file. -->

<!-- Begin Repeat -->
<Animation>
<Name /><!-- STRING -->
<!-- Mnemonic representation of data. -->

<Code /><!-- INTEGER -->
<!-- Integer code corresponding to "Name" -->

<!-- Both of those are used by the program when encoding XML->KFM -->
</Animation>
<!-- End Repeat -->
</AnimCodes>


Update - 2008.02.19


2008.02.19

Added a Tutorial.

2008.02.18

Fixed a bug with the <Variation> tags, where they weren't encoding to KFM format properly.




Links
Animation Code List (http://forums.civfanatics.com/showthread.php?p=6540433#post6540455)
Tutorial, Source and Executable (http://forums.civfanatics.com/downloads.php?do=file&id=8747)

GarretSidzaka
Feb 18, 2008, 01:48 PM
WHOA!!! :crazyeye:

please please please please take the time to explain to me how to do this!! :worship:

And i am adding this to next weeks Modcast episode!! :goodjob:

woodelf
Feb 18, 2008, 03:10 PM
I'm with Tony. I need a bit more info, but it looks awesome.

esemjay
Feb 19, 2008, 03:49 AM
Tutorial is uploaded in ZIP format, along with a sample Mod to work with. Just extract the mod into your Civ4 Mod folder. The shortcut included assumes that your Civ4 executable file is at:

C:/Program Files/Firaxis Games/Civilization 4/Beyond the Sword/

But it's included to let you launch the mod without having to start up Civ4 then load the mod.

asioasioasio
Feb 19, 2008, 08:14 AM
What can be done with this tool?
New animations could be added toe xisting one?

For example to add military unit additional workers animations?
Or i can't mix animations from different unit?

BTW this tool looks great and will trully come in handy.

esemjay
Feb 19, 2008, 12:10 PM
The tutorial I uploaded shows you how to add an attack animation to the worker, then lets you see the results first hand.

Mixing animations is possible, but sometimes you get weird results, because not all models are boned the same way. For example, adding paradrop to the NavySeal will have un-natural bending of the shoulders for some reason. You can see that in 3DS Max.

I don't have a lot of experience in modeling, though- so the tutorial uses a standard animation- "Chop" for the attack animation. It's included in the package as "Worker_MD_StrikeA.KF" ; and there have been a couple of XML changes to make the Worker fight instead of surrender.

The changes are done to a copy of the worker, named "Worker Alt"; and they are to the <Combat>, <iCombat> and <iCombatLimit> tags - and they're done to a mod that I included so that you don't accidentally break Civ4.

GarretSidzaka
Feb 19, 2008, 12:21 PM
would it be possible to give units that don't have attack animation some combat ability? Like settlers that can defend themselves?

and i want to make missionaries and great people models animate with both the unit action button and combat sequences

asioasioasio
Feb 19, 2008, 12:28 PM
Yeah i think so - but as esemjay said not always it'll work - because of bones.

Yeah i watched tutorial - and i'm pritty impressed. time to learn military engineer with flamethrower diging, choppping and using pickaxe :) Tough i'm not sure if this will work - but i need to try :)

It sounds like brakethroug - it's always easier to edit one animation and attach it in .kfm than producing sequence of animations.

esemjay
Feb 19, 2008, 12:35 PM
would it be possible to give units that don't have attack animation some combat ability? Like settlers that can defend themselves?

and i want to make missionaries and great people models animate with both the unit action button and combat sequences
Yes- the Worker actually has no combat animations. The tutorial shows you how to give the Worker combat ability; this should be able to be done with Settlers as well.

Yeah i think so - but as esemjay said not always it'll work - because of bones.

Yeah i watched tutorial - and i'm pritty impressed. time to learn military engineer with flamethrower diging, choppping and using pickaxe :) Tough i'm not sure if this will work - but i need to try :)

It sounds like brakethroug - it's always easier to edit one animation and attach it in .kfm than producing sequence of animations.

That's what I was aiming for :)

seZereth
Feb 21, 2008, 10:45 AM
The problem I still see is the Visibility of Objects.
Like a weapon for the worker. It has to be visible while fighting, but invisible while doing everything else.
And that problem with the strange BIP/Bip01 naming of the bones has been getting on my nerves from the beginning of modding on... why didnt they simply use one rig for fully easily interchangeable animations :( ???

I will see if I can get a Bajonette Attack for the Infantry and Oromo warrior to work... for our WW1 mod :D
thanks in advance.

johny smith
Feb 23, 2008, 12:19 PM
Just wanted to say this really helped for me with the flaming pig unit. It made it so simple. Before for some reason the flaming pig turned into a bear with the low graphics setting. It was using the bear.kfm. Just decoded the bear.kfm, and renamed the NIF. Thank you.

Here is the link for the unit is anyone is interested.
http://forums.civfanatics.com/showthread.php?t=194673

GarretSidzaka
Feb 24, 2008, 02:19 PM
hey listen to the next modcast and reply to us PLZ :) !!!

esemjay
Feb 25, 2008, 03:49 AM
When does it air?

Thomas SG
Feb 25, 2008, 06:16 AM
Hi, great tool. But although it works I've go to tell you that the *.xml that your programm creats is displayed absolutly wrong on my station. My xml are looking absolutly silly. But until I can identify all information it doesn't matter.

Great job.:goodjob:

hrochland
Feb 25, 2008, 07:33 AM
you can use dreamweaver or some programm which works with XML
I use DZsoft... but there is more such programs... :)

esemjay
Feb 25, 2008, 10:40 AM
I use Visual Web Developer 2008 Express to edit XML.

I am curious, though, what you mean that they are coming out wrong?

GarretSidzaka
Feb 27, 2008, 12:51 AM
ESEMJAY!!!

I just used your konverter and look what i made for you:

GarretSidzaka
Feb 27, 2008, 01:06 AM
here are some definitions of the event triggers.

Also in the next few posts are all the kfm event flowcharts, resized.


Category BaseID A (Value) B(Value) C (Value)
Idle 0 1000 2000 3000
Fidget 1 1001 2001 3001
Surrender 2 1002 2002 3002
IdleDie 3 1003 2003 3003
IdleDie_Fade 4 1004 2004 3004

Run 10 1010 2010 3010
RunDie 12 1012 2012 3012
RunDie_Fade 13 1013 2013 3013

Fortify 20 1020 2020 3020
Fortify_Idle 21 1021 2021 3021
Strike 22 1022 2022 3022
Hurt 23 1023 2023 3023
Die 24 1024 2024 3024
Die_Fade 25 1025 2025 3025

RangedFortify 30 1030 2030 3030
Ranged_Idle 31 1031 2031 3031
RangedStrike 32 1032 2032 3032
RangedDie 33 1033 2033 3033
RangedDie_Fade 34 1034 2034 3034
RangedReturn 35 1035 2035 3035

Found 40 1040 2040 3040

IrrigateBegin 50 1050 2050 3050
Irrigate 51 1051 2051 3051
IrrigateRest 52 1052 2052 3052
BuildBegin 53 1053 2053 3053
Build 54 1054 2054 3054
BuildRest 55 1055 2055 3055
MineBegin 56 1056 2056 3056
Mine 57 1057 2057 3057
MineRest 58 1058 2058 3058
ChopBegin 59 1059 2059 3059
Chop 60 1060 2060 3060
ChopRest 61 1061 2061 3061
ShovelBegin 62 1062 2062 3062
Shovel 63 1063 2063 3063
ShovelRest 64 1064 2064 3064

GarretSidzaka
Feb 27, 2008, 01:10 AM
these flowcharts where in .tga format, so i moved em right over to jpg and uploaded them too :)

esemjay:

you might want to include these in your beginning post!

hrochland
Feb 27, 2008, 01:25 AM
for me is it hard too in start. I´m relying on your experiency, Garret :)

esemjay
Feb 27, 2008, 01:49 AM
these flowcharts where in .tga format, so i moved em right over to jpg and uploaded them too :)

esemjay:

you might want to include these in your beginning post!
To keep the XML files simple, KonFM just assumes that all animations can lead into all other animations; it only makes the KFM files ~1KB larger, but it made the XML more user friendly.

Thanks for that list, though! :D It's referenced in the first post now. I'm glad to see that people actually like KonFM :D

snipperrabbit!!
Feb 27, 2008, 03:19 AM
Hi, esemjay ! I noticed that Nifskope can display the kfm when selecting the right parameter in the view menu :

http://forums.civfanatics.com/uploads/105110/Kfm.png
Didn't know if it is usefull to you but thought it is a nice way to bookmark this thread.

And no, it is not possible yet to change things to the kfm window in Nifskope by right clicking (just names by double clicking :confused: ).

Anyway, :goodjob: , Thanks !

esemjay
Feb 27, 2008, 04:19 AM
That would've made things a lot easier! :P

GarretSidzaka
Feb 28, 2008, 08:48 PM
...
Thanks for that list, though! :D It's referenced in the first post now. I'm glad to see that people actually like KonFM :D

You're welcome. And I also featured you in the very next Modcast Episode for the podcasts. I have a whole segment where we talk about your project, so be sure to listen in :)

(maybe we can even get you to come onto the show :D )

GarretSidzaka
Feb 28, 2008, 08:49 PM
oh yeah, and check out the unit i made using your Konverter ;)

chuck norris (http://forums.civfanatics.com/showthread.php?t=265229)

esemjay
Feb 28, 2008, 10:13 PM
You're welcome. And I also featured you in the very next Modcast Episode for the podcasts. I have a whole segment where we talk about your project, so be sure to listen in :)

(maybe we can even get you to come onto the show :D )
If you can get me a date and time, I'll talk to you guys :P

GarretSidzaka
Feb 29, 2008, 12:04 AM
yeah, probly in about 4-5 weeks. keep in touch with me

you can reach me at ringworldwu with yahoo messenger :)

esemjay
Feb 29, 2008, 12:42 AM
Unfortunately, I won't be able to make it in that timeframe. I'm going to be unavailable for at least 6-8 weeks, starting in 3 weeks.

GarretSidzaka
Feb 29, 2008, 01:37 AM
what are you doing this upcomming sunday? thats when we record next

esemjay
Feb 29, 2008, 01:45 AM
I'm pretty sure I'm free Sunday

GarretSidzaka
Mar 01, 2008, 04:39 PM
allright, email me through my profile and i will respond with what you need for the show and when to show up :)

esemjay
Mar 10, 2008, 12:07 AM
These files are now re-uploaded to the database- the Tutorial, Executable, XML and such are now all in one file hosted on the site. The tutorial was previously inaccessible, since it was lost in the hacker attack. I'm sorry for any inconveniences that may have caused.