View Full Version : Esemjay's KFM Converter


esemjay
Feb 13, 2008, 12:19 AM
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, 02: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, 04:10 PM
I'm with Tony. I need a bit more info, but it looks awesome.

esemjay
Feb 19, 2008, 04: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, 09: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, 01: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, 01: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, 01: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, 01: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, 11: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, 01: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, 03:19 PM
hey listen to the next modcast and reply to us PLZ :) !!!

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

Thomas SG
Feb 25, 2008, 07: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, 08: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, 11: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, 01:51 AM
ESEMJAY!!!

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

GarretSidzaka
Feb 27, 2008, 02: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, 02: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, 02:25 AM
for me is it hard too in start. I´m relying on your experiency, Garret :)

esemjay
Feb 27, 2008, 02: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, 04: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, 05:19 AM
That would've made things a lot easier! :P

GarretSidzaka
Feb 28, 2008, 09: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, 09: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, 11: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, 01: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, 01: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, 02:37 AM
what are you doing this upcomming sunday? thats when we record next

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

GarretSidzaka
Mar 01, 2008, 05: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, 01: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.

Bangra 7
Sep 12, 2008, 04:45 PM
Thanks for the Converter. Putting it to use right now!

WilliamOfOrange
Oct 19, 2009, 03:44 PM
This is sweet! I tried playing around with using Strike B or C (changing the numbers, too), but the worker just hunches or stands there. I was just curious if it was possible to get the worker to attack with the shovel or axe. I just wanted to know the reason it is the axe in this case, because I wanted to know what else was possible.

It's probably a bit more involved, but could we have them attacking with maces or spears?

Thanks again for the converter!

esemjay
Oct 19, 2009, 07:03 PM
Thank you, it's been a while since I've done any development on this. I intended to put out a KonverterFM v2 but got caught up in other things. Basically, I was planning on doing a real-time updater that didn't need XML manipulation on the user's part.

I chose the axe animation, because it already looks like an attack animation. The shovel and rake just didn't seem menacing enough. I'm not entirely sure why it resulted in them just standing still- but the hunch is the "skip turn" animation. Adding maces and spears is THEORETICALLY possible, but requires manipulation of the actual .nif files, I believe. I'm 100% sure you COULD add in additional items, but I never figured out how to get them to show up during the animations. I ended up with Navy SEAL's parachuting in with no parachutes.

smeagolheart
Sep 09, 2010, 06:31 PM
I realize this thread hasn't been touched in a long time, but it seems to be the only tool there is for KFM modification that I can see soooooo.

I can't run the program. I'm running win7 64bit. I open a kfm with it and get this error.

http://i543.photobucket.com/albums/gg445/smeagolheart/scren.jpg

Am I doing it wrong? Anyone else get this error?

esemjay
Sep 10, 2010, 12:30 AM
I actually do not support this product anymore. This project was originally developed on Windows XP by reverse engineering the KFM files in a hex editor, and cross-referencing the results between multiple animation files until I had documented (almost) every byte in the file. If memory serves, there was only a small portion of the file that went undocumented. If the 32 bit and 64 bit operating systems require different types of KFM file, then the program will not work. I don't see that being the case, but stranger things have happened.

In any case, it works on my Windows7 32bit O/S.

The error, however, implies that the exception was while disassembling the KFM file. There is literally NO custom code between the "Select KFM file" and KonverterFM. It's Window's select file dialog box. The entire interface, as the user sees it, was a frontend to a C++ version of the program that ran as a command-line tool and was converted to C#; so if you're going to experience an error before Decoding/Encoding, it's going to be a permissions issue (Windows isn't allowing you to open those files)

If, however, it's a program issue in the disassembly process, it either points (again) to a permissions issue, that Windows doesn't know how to operate this program, OR that the file is using a different format from what I designed this tool to read/write. The following steps should remedy all but the last case, and I don't use a 64bit operating system; nor do I have the documentation for KFM files anymore.

Hopefully, the following steps will solve your problem.

If you are working on a copy in your Program Files tree, try copying the file out of your Program Files to a working folder that you "Own" and have admin rights to; that way, if it's a permissions issue, you can do the changes and copy them into the "Game's" folder when you are done editing.

If that does not solve the issue, try running it in 32-bit compatibility mode.

If that still does not solve the issue, try running it in WindowsXP compatibility mode.

If that STILL does not work, try running it in 32-bit Windows XP compatibility mode as an administrator.

The ONLY error-catching this program has is to prevent you from trying to decode a KFM file that does not exist. Other than that, it will encode EXACTLY what you tell it to. If you don't finish your XML file, it won't finish the KFM file; if you have errors in the XML, it'll encode those errors; if you encode a blank XML file, you'll get a "Blank" KFM file.

smeagolheart
Sep 10, 2010, 04:44 PM
I tried various compatiblity modes and the windows xp mode virtual machine thing. They all gave the same error reading past EOF thing. I'm trying to decode leaderhead kfms, am I doing it wrong?

esemjay
Sep 10, 2010, 10:36 PM
It wasn't designed for the leaderhead KFM's. It was only tested on units.

smeagolheart
Sep 11, 2010, 12:19 AM
ah I see