Talk:DBPF/Source Code

From SimsWiki
Jump to: navigation, search

Me again :-) I will ask something about this code.

When you read the Index, this sequence of operations is used:

  $indexData[$i]['typeID'] = $this->revhex($this->strhex(fread($handle, 4)));
  $indexData[$i]['groupID'] = $this->revhex($this->strhex(fread($handle, 4)));
  $indexData[$i]['instanceID'] = $this->revhex($this->strhex(fread($handle, 4)));

  if ($this->indexMajorVersion == "7") && ($this->indexMinorVersion == "1")) {
    $indexData[$i]['instanceID2'] = $this->revhex($this->strhex(fread($handle, 4)));
  }
  $indexData[$i]['offset'] = $this->read_UL4($handle);
  $indexData[$i]['filesize'] = $this->read_UL4($handle);
  $indexData[$i]['compressed'] = false;
  $indexData[$i]['truesize'] = 0;

and then, when you read the DIR resource, almost exactly the same sequence is done:

  $typeID = $this->revhex($this->strhex(fread($handle, 4)));
  $groupID = $this->revhex($this->strhex(fread($handle, 4)));
  $instanceID = $this->revhex($this->strhex(fread($handle, 4)));
  if (($this->indexMajorVersion == "7") && ($this->indexMinorVersion == "1")) {
    $instanceID2 = $this->revhex($this->strhex(fread($handle, 4)));
  }
  $filesize_nc = $this->read_UL4($handle);

and finally you check if the file is compressed by comparing the fields.

So, if I created a routine to read the whole sequence (except that the DIR does not read the offset), and then checked if the file is compressed using an overloaded "==" operator, would it be wrong? I think it might improve the readability of the code. Albmont 15:36, 1 January 2007 (EST)

You could certainly create a function to grab those 4 things and return them in an array. It's duplicate code becuase, essentially, it's duplicate data - as we discussed on the DBPF page, it doesn't neccesarily make sense from a coders point of view. :) Delphy 16:13, 1 January 2007 (EST)

Delphy, thanks for this code, and much more importantly to me, the reference to the original perl code! I'm writing some stuff in perl, so that's more useful to me at the moment.... mjshannon3 2007-01-05 21:53 EST

Where is the original perl code? Albmont 16:05, 16 January 2007 (CST)
http://hullabaloo.simshost.com/forum/viewtopic.php?t=6578&postdays=0&postorder=asc Delphy 05:46, 17 January 2007 (CST)
There is no perl code in that page. Albmont 07:10, 17 January 2007 (CST)
Second page, 4th one down. Delphy 07:16, 17 January 2007 (CST)
Thanks! It's deeply hidden, isn't it? Albmont 07:55, 17 January 2007 (CST)
Yeah it took me ages to find actual code that worked, since SimPE is basically impossible to read, and no other working code existed. Delphy 15:31, 17 January 2007 (CST)

R (programming language)

I tried to work with the php and the perl code, but my understanding of those languages is too rude. But I could duplicate their functionality in the R programming language. Is anyone interested in the code? Albmont 14:20, 20 January 2007 (CST)

Yes please! I'm interested in learning anything I can about cross platform languages, and I'm currently engaged in a project to make some new sims 2 related programs in which the Basic I/O functions for the packages will all be in C. However, I'm open to learning about anything else as well! :D --Jfade 23:44, 20 January 2007 (CST)
I will do more than that. I will post in Detect Pets Body Shop bug/Source Code the code of the R script that seeks and detects which packages were created with the Pets EP Bodyshop, that must be fixed using SimPE. Albmont 13:00, 21 January 2007 (CST)
Ah, very cool! Thanks for that, it's always interesting to me to see how other people code, and how convoluted my stuff looks in comparison, LOL. I'll have to take some time to look it over really carefully and see what I can decipher from it. The R language looks very interesting though. Out of curiosity, what other programming languages do you use? --Jfade 13:51, 21 January 2007 (CST)
What languages? All of them! :-) But of course some are harder to understand, while others are harder to create stuff. I tried to adapt dmchess's perl code, but I couldn't do some basic stuff. I think I haven't grokked perl - I can write some code, but sometimes the code doesn't work and I have no clue for the reason. Albmont 17:18, 21 January 2007 (CST)
Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox