1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Esemjay's KFM Converter

Discussion in 'Civ4 - Utility Programs' started by esemjay, Feb 13, 2008.

  1. esemjay

    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
     

    Attached Files:

  2. GarretSidzaka

    GarretSidzaka Deity

    Joined:
    Dec 17, 2002
    Messages:
    4,696
    Location:
    Arizona
    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:
     
  3. woodelf

    woodelf Bard Retired Moderator

    Joined:
    Jun 12, 2003
    Messages:
    15,036
    Location:
    Gallery
    I'm with Tony. I need a bit more info, but it looks awesome.
     
  4. esemjay

    esemjay Prince

    Joined:
    Jan 24, 2008
    Messages:
    386
    Location:
    USA
    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.
     
    Damagemax likes this.
  5. asioasioasio

    asioasioasio Fallout Scrubber

    Joined:
    Mar 4, 2006
    Messages:
    3,058
    Location:
    Poland, EU
    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.
     
  6. esemjay

    esemjay Prince

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

    GarretSidzaka Deity

    Joined:
    Dec 17, 2002
    Messages:
    4,696
    Location:
    Arizona
    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
     
  8. asioasioasio

    asioasioasio Fallout Scrubber

    Joined:
    Mar 4, 2006
    Messages:
    3,058
    Location:
    Poland, EU
    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.
     
  9. esemjay

    esemjay Prince

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

    That's what I was aiming for :)
     
  10. seZereth

    seZereth FfH´s art monk(ey)

    Joined:
    Feb 3, 2006
    Messages:
    3,900
    Location:
    Bayreuth
    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.
     
    Damagemax likes this.
  11. johny smith

    johny smith Deity

    Joined:
    Mar 10, 2007
    Messages:
    2,273
    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
     
  12. GarretSidzaka

    GarretSidzaka Deity

    Joined:
    Dec 17, 2002
    Messages:
    4,696
    Location:
    Arizona
    hey listen to the next modcast and reply to us PLZ :) !!!
     
  13. esemjay

    esemjay Prince

    Joined:
    Jan 24, 2008
    Messages:
    386
    Location:
    USA
    When does it air?
     
  14. Thomas SG

    Thomas SG CCV-designer

    Joined:
    Aug 10, 2007
    Messages:
    1,164
    Location:
    Germany
    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:
     
  15. hrochland

    hrochland Prince

    Joined:
    Apr 9, 2006
    Messages:
    2,233
    Location:
    Czech Kingdom
    you can use dreamweaver or some programm which works with XML
    I use DZsoft... but there is more such programs... :)
     
  16. esemjay

    esemjay Prince

    Joined:
    Jan 24, 2008
    Messages:
    386
    Location:
    USA
    I use Visual Web Developer 2008 Express to edit XML.

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

    GarretSidzaka Deity

    Joined:
    Dec 17, 2002
    Messages:
    4,696
    Location:
    Arizona
    ESEMJAY!!!

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

    Attached Files:

  18. GarretSidzaka

    GarretSidzaka Deity

    Joined:
    Dec 17, 2002
    Messages:
    4,696
    Location:
    Arizona
    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
     

    Attached Files:

  19. GarretSidzaka

    GarretSidzaka Deity

    Joined:
    Dec 17, 2002
    Messages:
    4,696
    Location:
    Arizona
    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!
     

    Attached Files:

  20. hrochland

    hrochland Prince

    Joined:
    Apr 9, 2006
    Messages:
    2,233
    Location:
    Czech Kingdom
    for me is it hard too in start. I´m relying on your experiency, Garret :)
     

Share This Page