<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://www.simswiki.info/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://simswiki.info/index.php?action=history&amp;feed=atom&amp;title=CPF%2FSource_Code</id>
		<title>CPF/Source Code - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://simswiki.info/index.php?action=history&amp;feed=atom&amp;title=CPF%2FSource_Code"/>
		<link rel="alternate" type="text/html" href="http://simswiki.info/index.php?title=CPF/Source_Code&amp;action=history"/>
		<updated>2026-04-27T09:07:18Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.2</generator>

	<entry>
		<id>http://simswiki.info/index.php?title=CPF/Source_Code&amp;diff=13828&amp;oldid=prev</id>
		<title>Jfade: Added some code of my own in C#, yay.</title>
		<link rel="alternate" type="text/html" href="http://simswiki.info/index.php?title=CPF/Source_Code&amp;diff=13828&amp;oldid=prev"/>
				<updated>2007-01-26T22:10:07Z</updated>
		
		<summary type="html">&lt;p&gt;Added some code of my own in C#, yay.&lt;/p&gt;
&lt;a href=&quot;http://simswiki.info/index.php?title=CPF/Source_Code&amp;amp;diff=13828&amp;amp;oldid=13098&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Jfade</name></author>	</entry>

	<entry>
		<id>http://simswiki.info/index.php?title=CPF/Source_Code&amp;diff=13098&amp;oldid=prev</id>
		<title>Albmont: /* Source */</title>
		<link rel="alternate" type="text/html" href="http://simswiki.info/index.php?title=CPF/Source_Code&amp;diff=13098&amp;oldid=prev"/>
				<updated>2007-01-21T00:42:04Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Source&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 00:42, 21 January 2007&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 8:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 8:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;?&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;#&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;#&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 67:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 66:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;?&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Albmont</name></author>	</entry>

	<entry>
		<id>http://simswiki.info/index.php?title=CPF/Source_Code&amp;diff=13097&amp;oldid=prev</id>
		<title>Albmont: First version, shamelessly copied from the DBPF/Source Code page</title>
		<link rel="alternate" type="text/html" href="http://simswiki.info/index.php?title=CPF/Source_Code&amp;diff=13097&amp;oldid=prev"/>
				<updated>2007-01-21T00:41:23Z</updated>
		
		<summary type="html">&lt;p&gt;First version, shamelessly copied from the DBPF/Source Code page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Overview=&lt;br /&gt;
&lt;br /&gt;
This page contains a sample [http://en.wikipedia.org/wiki/R_(programming_language) R] function to read a [[CPF]] and extract information about it.&lt;br /&gt;
&lt;br /&gt;
Use at your own risk. Any comments please use the [[Talk:CPF/Source Code]] page.&lt;br /&gt;
&lt;br /&gt;
=Source=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# raw is a list of bytes (raw format). They&lt;br /&gt;
# should have been read by readBin(f, &amp;quot;raw&amp;quot;, n) or&lt;br /&gt;
# using a decompressing routine&lt;br /&gt;
#&lt;br /&gt;
# The return value is a list, with &amp;quot;human&amp;quot; as a human-readable&lt;br /&gt;
# list of things in the CPF.&lt;br /&gt;
#&lt;br /&gt;
convert_cpf &amp;lt;- function(raw)&lt;br /&gt;
{&lt;br /&gt;
  cpf &amp;lt;- NULL&lt;br /&gt;
  cpf$id &amp;lt;- &amp;quot;CPF&amp;quot;&lt;br /&gt;
  cpf$version &amp;lt;- get_little_endian(raw, 2)&lt;br /&gt;
  n &amp;lt;- get_little_endian(raw[3:6], 4) # number of entries&lt;br /&gt;
  cpf$data &amp;lt;- NULL&lt;br /&gt;
  pos &amp;lt;- 7  # first 6 bytes are version and number of fields&lt;br /&gt;
  # start decoding at position 7&lt;br /&gt;
  for (i in 1:n) {&lt;br /&gt;
    xtype &amp;lt;- get_little_endian(raw[pos:(pos+3)], 4)&lt;br /&gt;
    # xtype is the type of the data, in a crazy hex code&lt;br /&gt;
    pos &amp;lt;- pos + 4&lt;br /&gt;
    # after each interpretation of raw bytes, we should move pos&lt;br /&gt;
    nlen &amp;lt;- get_little_endian(raw[pos:(pos+3)], 4)  # len of field name&lt;br /&gt;
    pos &amp;lt;- pos + 4&lt;br /&gt;
    name &amp;lt;- rawToChar(raw[pos:(pos+nlen-1)])&lt;br /&gt;
    pos &amp;lt;- pos + nlen&lt;br /&gt;
    if (xtype == 0xEB61E4F7 || xtype == 0x0C264712 || xtype == 0xABC78708) {  # integer or float&lt;br /&gt;
# Nota Bene: I didn't care for float data, I just read and ignore&lt;br /&gt;
      data &amp;lt;- get_little_endian(raw[pos:(pos+3)], 4)&lt;br /&gt;
      pos &amp;lt;- pos + 4&lt;br /&gt;
      cpf[[name]] &amp;lt;- data&lt;br /&gt;
    }&lt;br /&gt;
    else if (xtype == 0x0B8BEA18) { # string&lt;br /&gt;
# get string length&lt;br /&gt;
      slen &amp;lt;- get_little_endian(raw[pos:(pos+3)], 4)&lt;br /&gt;
      pos &amp;lt;- pos + 4&lt;br /&gt;
      str &amp;lt;- rawToChar(raw[pos:(pos+slen-1)])&lt;br /&gt;
      pos &amp;lt;- pos + slen&lt;br /&gt;
      cpf[[name]] &amp;lt;- str&lt;br /&gt;
    }&lt;br /&gt;
    else if (xtype == 0xCBA908E1) { # boolean&lt;br /&gt;
      cpf[[name]] &amp;lt;- raw[pos]&lt;br /&gt;
      pos &amp;lt;- pos + 1&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return(cpf)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
# get_little_endian converts n bytes in little-endian&lt;br /&gt;
# format. It means that the first byte is the less significant&lt;br /&gt;
#&lt;br /&gt;
get_little_endian &amp;lt;- function(bytes, n)&lt;br /&gt;
{&lt;br /&gt;
  return(sum(256^(0:(n-1)) * as.integer(bytes[1:n])))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
&lt;br /&gt;
* [[CPF]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Source Code]]&lt;/div&gt;</summary>
		<author><name>Albmont</name></author>	</entry>

	</feed>