FLUTF

 view release on metacpan or  search on metacpan

lib/Games/Freelancer/UTF.pm  view on Meta::CPAN

		croak "NOT a UTF File";
	}
	
}

#Writes an UTF file with header and nodes.

=head2 UTFwriteUTF (TREE(HASHREF) )

Calls UTFwriteUTFrek and then return the header, TREE, STRINGLIB and DATALIB 

=cut 

sub UTFwriteUTF{
	my $tree=shift;
	my $i=0;
	$strings="";
	$datas="";
	my $code = "";
	%strings = ();
	%datas = ();
	$pointer=0;
	my @list = keys(%$tree);
	foreach (0 .. $#list) {
		$code.=UTFwriteUTFrek($tree->{$list[$_]},$list[$_],($_!=$#list));
	}
	my $string=$strings;
	$string.="\0" for(length($strings) .. (int(length($strings)/32)+1)*32); #Just some fun stuff.
	return "UTF ".pack("VVVVVVVVVV",0x101,44+12,length($code),0,44,44+12+length($code),length($string),length($strings),44+12+length($code)+length($string),0)."000000000000".$code.$string.$datas;
	
}

1;

__END__

=head1 Example tree

This is an example of deparsed tree of a very basic model (.cmp) a friend of mine made, there are however other types of UTF files.

Every UTF file seems to have a root node called \.

	$tree = {
	    '\\' => {
	        'VMeshLibrary' => {
	            'jc_defender.lod0.vms' => { #Contains the model data
	                'VMeshData' => 'Some Vmeshdata' #Removed by me because you can't see anything useful here and its large.
	            }
	        },
	        'Cmpnd' => {
	            'Root' => {
	                'File name' => 'jc_defender.3db�', #Links the frist model
	                'Index' => '��������', #Index 0
	                'Object name' => 'Root�' #Name of that model.
	            }
	        },
	        'jc_defender.3db' => { #A model, a file can have multiple .3db (model) files in them
	            'Hardpoints' => { #The game lets you mount things on this Points
	                'Fixed' => { #Not rotatebale
	                    'HpEngine01' => {
	                        #These are just packed vectors, can be easily decoded using unpack("f*",this)
	                        'Orientation' => '��€?��������������€?��������������€?',
	                        'Position' => '����IK¿×A' #also a vector: unpack("f*",this)
	                    },
	                }
	                'Revolute' => { #For weapons mostly, follow the cursor.
	                    'HpWeapon01' => {
	                        'Axis' => '������€?����', #also a vector: unpack("f*",this)
	                        'Max' => '’†>����', #an angle in radians: unpack("f*",this)
	                        'Min' => '’†¾����',
	                        'Orientation' => 'Z|¿âÐ1¾���€âÐ1>Z|¿�����������€��€?', #also a vector: unpack("f*",this)
	                        'Position' => '­L€?Œø®>¿+±À' #also a vector: unpack("f*",this)
	                    },
	                    'HpWeapon02' => {
	                        'Axis' => '������€?����',
	                        'Max' => '’†>����',
	                        'Min' => '’†¾����',
	                        'Orientation' => 'Z|¿âÐ1>����âÐ1¾Z|¿��������������€?', 
	                        'Position' => 'r¿Œø®>¿+±À'
	                    }
	                }
	            },
	            'MultiLevel' => {
	                'Level0' => {
	                    'VMeshPart' => {
	                        #This contains a reference to the VMeshdata up there
	                        'VMeshRef' => '<���Úý��x��n
���¯Ë@ĝËÀ“°š?d÷¤¿-¬Aï7Á�`Ž:m$½€ð¢½ä,A'
	                    }
	                }
	            }
	        }
	    }
	};

I cut out the VMesh part which is just binary data, but it can be read using L<Games::Freelancer::VMesh>

=head1 SEE ALSO

L<Games::Freelancer::VMesh> for in UTF files included VMeshData and VMeshRef values.

L<Games::Freelancer::BINI> for another type of file used by Freelancer.

=head1 LICENSE

UTF.pm is published under the terms of the MIT license, which basically 
means "Do with it whatever you want". For more information, see the license.txt
file that should be enclosed with this distribution. A copy of the license
is (at the time of this writing) also available at
L<http://www.opensource.org/licenses/mit-license.php>.

=head1 AUTHOR

Marc "Maluku" Sebastian Lucksch
perl@marc-s.de

=cut



( run in 3.688 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )