Esemjay's KFM Converter

esemjay

Prince
Joined
Jan 24, 2008
Messages
386
Location
USA
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.

Spoiler Tutorial :

Step 1: Open KFM Utility


Step 2: Click "Open" for the KFM Field.


Step 3: Find and open the KFM file you wish to edit. This file must exist to decode.


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.


Step 5: Press the "Decode" button to convert from KFM to XML.


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
Code:
<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
Code:
<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
Spoiler :

  • 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
Tutorial, Source and Executable
 

Attachments

  • KonverterFM.zip
    134.9 KB · Views: 1,232
  • KonverterFM-Source.zip
    149.3 KB · Views: 628
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.
 
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.
 
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.
 
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
 
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.
 
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 :)
 
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.
 
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
 
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:
 
I use Visual Web Developer 2008 Express to edit XML.

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

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

Attachments

  • proofofconcept.jpg
    proofofconcept.jpg
    200.1 KB · Views: 637
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
 

Attachments

  • motionflow_melee.jpg
    motionflow_melee.jpg
    48.5 KB · Views: 507
  • motionflow_ranged.jpg
    motionflow_ranged.jpg
    49.3 KB · Views: 475
  • motionflow_aircraft.jpg
    motionflow_aircraft.jpg
    27 KB · Views: 408
  • motionflow_settler.jpg
    motionflow_settler.jpg
    42.1 KB · Views: 638
  • motionflow_worker.jpg
    motionflow_worker.jpg
    77.7 KB · Views: 490
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!
 

Attachments

  • motionflow_aircraft.jpg
    motionflow_aircraft.jpg
    21.6 KB · Views: 475
  • motionflow_greatpeople.jpg
    motionflow_greatpeople.jpg
    49.5 KB · Views: 356
  • motionflow_tank.jpg
    motionflow_tank.jpg
    37.4 KB · Views: 680
Top Bottom