Packages

  • package root
    Definition Classes
    root
  • package io
    Definition Classes
    root
  • package github
    Definition Classes
    io
  • package memo33
    Definition Classes
    github
  • package scdbpf

    Provides methods for accessing and modifying the contents of DBPF formatted files.

    Provides methods for accessing and modifying the contents of DBPF formatted files. Currently, only DBPF version 1.0 is supported (used by SimCity 4).

    DBPF files are accessed via DbpfFiles, a container of DbpfEntries. The content of a DbpfEntry can be accessed from BufferedEntries in decoded form as DbpfType, such as Exemplar, Fsh or Sc4Path.

    This package object provides additional type aliases for DbpfExceptions.

    Examples

    To get started, it is easiest to start the REPL via sbt console, which loads all the dependencies and useful initial import statements. Reading a DBPF file, sorting its entries by TGI and writing back to the same file could be achieved like this:

    val dbpf = DbpfFile.read(new File("foobar.dat"))
    dbpf.write(dbpf.entries.sortBy(_.tgi))

    This example shifts the GIDs of all LTexts by +3:

    dbpf.write(dbpf.entries.map { e =>
      if (e.tgi matches Tgi.LText)
        e.copy(e.tgi.copy(gid = e.tgi.gid + 3))
      else
        e
    })

    Another example: This decodes all the Sc4Path entries and rotates them by 90 degree.

    val writeList = for (e <- dbpf.entries) yield {
      if (e.tgi matches Tgi.Sc4Path) {
        val be = e.toBufferedEntry.convertContentTo(Sc4Path)
        be.copy(content = be.content * RotFlip.R1F0)
      } else {
        e
      }
    }
    dbpf.write(writeList)

    The following example finds the first entry that is an exemplar and contains a property with a specific ID. (Note the view to avoid unnecessary decoding if the exemplar is already among the first entries.)

    val id = UInt(0x12345678)
    dbpf.entries.view.
      filter(_.tgi matches Tgi.Exemplar).
      map(_.toBufferedEntry.convertContentTo(Exemplar)).
      find(_.content.properties.contains(id))
    Definition Classes
    memo33
  • package compat
  • BufferedEntry
  • DbpfEntry
  • DbpfExceptions
  • DbpfFile
  • DbpfPackager
  • DbpfProperty
  • DbpfType
  • DbpfTypeCompanion
  • DbpfUtil
  • Exemplar
  • Experimental
  • Fsh
  • LText
  • RawEntry
  • RawType
  • S3d
  • Sc4Path
  • StreamedEntry
  • Tgi
  • TgiMask
  • WithContentConverter

package scdbpf

Provides methods for accessing and modifying the contents of DBPF formatted files. Currently, only DBPF version 1.0 is supported (used by SimCity 4).

DBPF files are accessed via DbpfFiles, a container of DbpfEntries. The content of a DbpfEntry can be accessed from BufferedEntries in decoded form as DbpfType, such as Exemplar, Fsh or Sc4Path.

This package object provides additional type aliases for DbpfExceptions.

Examples

To get started, it is easiest to start the REPL via sbt console, which loads all the dependencies and useful initial import statements. Reading a DBPF file, sorting its entries by TGI and writing back to the same file could be achieved like this:

val dbpf = DbpfFile.read(new File("foobar.dat"))
dbpf.write(dbpf.entries.sortBy(_.tgi))

This example shifts the GIDs of all LTexts by +3:

dbpf.write(dbpf.entries.map { e =>
  if (e.tgi matches Tgi.LText)
    e.copy(e.tgi.copy(gid = e.tgi.gid + 3))
  else
    e
})

Another example: This decodes all the Sc4Path entries and rotates them by 90 degree.

val writeList = for (e <- dbpf.entries) yield {
  if (e.tgi matches Tgi.Sc4Path) {
    val be = e.toBufferedEntry.convertContentTo(Sc4Path)
    be.copy(content = be.content * RotFlip.R1F0)
  } else {
    e
  }
}
dbpf.write(writeList)

The following example finds the first entry that is an exemplar and contains a property with a specific ID. (Note the view to avoid unnecessary decoding if the exemplar is already among the first entries.)

val id = UInt(0x12345678)
dbpf.entries.view.
  filter(_.tgi matches Tgi.Exemplar).
  map(_.toBufferedEntry.convertContentTo(Exemplar)).
  find(_.content.properties.contains(id))
Source
package.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. scdbpf
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Package Members

  1. package compat

Type Members

  1. final case class BufferedEntry[+A <: DbpfType](tgi: Tgi, content: A, compressed: Boolean) extends DbpfEntry with Product with Serializable

    A buffered entry whose data is held in memory in uncompressed form.

    A buffered entry whose data is held in memory in uncompressed form. The actual data will be held by the content type. As such, this entry will be immutable, if its content is immutable.

    A

    the type of the content

    tgi

    the TGI of this entry

    content

    the actual content of this entry

    compressed

    true, if the input should try to return the data in compressed form. If compression fails (if the compressed data would be larger than the compressed one, for instance), the data may be uncompressed nevertheless.

    See also

    RawEntry

    StreamedEntry

  2. type DbpfDecodeFailedException = scdbpf.DbpfExceptions.DbpfDecodeFailedException
  3. trait DbpfEntry extends AnyRef

    The base trait for entries of a DBPF file.

  4. type DbpfException = scdbpf.DbpfExceptions.DbpfException
  5. class DbpfFile extends AnyRef

    A container for DbpfEntries that are read from and written to a file.

    A container for DbpfEntries that are read from and written to a file. Instances of this class may be obtained via the DbpfFile.read method. The write methods may be used for writing entries back to a file.

    A DbpfFile is immutable, but the entries of this file might not be.

  6. type DbpfFileFormatException = scdbpf.DbpfExceptions.DbpfFileFormatException
  7. type DbpfIoException = scdbpf.DbpfExceptions.DbpfIoException
  8. type DbpfStreamOutOfDateException = scdbpf.DbpfExceptions.DbpfStreamOutOfDateException
  9. trait DbpfType extends AnyRef

    The base trait for the content type of DbpfEntries.

    The base trait for the content type of DbpfEntries.

    See also

    BufferedEntry

  10. trait DbpfTypeCompanion[B <: DbpfType] extends WithContentConverter[B]

    This trait defines the converters that should be implemented by companion objects of DbpfTypes.

  11. type ExceptionHandler = scdbpf.compat.ExceptionHandler
  12. sealed trait Exemplar extends DbpfType
  13. trait Fsh extends DbpfType
  14. sealed trait LText extends DbpfType
  15. final class RawEntry extends DbpfEntry

    A buffered entry whose raw byte data is held in an array, that is, the exact data that would be written to a file (compressed or uncompressed).

    A buffered entry whose raw byte data is held in an array, that is, the exact data that would be written to a file (compressed or uncompressed).

    This differs from a BufferedEntry in that the latter always holds the uncompressed data. Thus, a BufferedEntry is suited for access and modification of the content, but a RawEntry is usually suitable for just holding the data in memory, as creating the input does not require an intermediate compression. If the data is not compressed, this distinction is not as important.

    Instances of this class are immutable, if the data it was created from was. Note that conversion between RawEntries and BufferedEntries references the same backing array if possible. If created from a StreamedEntry, a new data array will be created, hence, the entry will be immutable.

    See also

    BufferedEntry

    StreamedEntry

  16. class RawType extends DbpfType

    A raw type that does not represent any specific format.

    A raw type that does not represent any specific format. Its data is backed by an array. As such, it is also suited as a super class of specialized types which are backed by an array.

    Instances of this class my be obtained via the companion object.

    Note

    This is one of the few spots where the raw backing array gets exposed. If instances of this class or created from instances of this class are meant to be immutable, it is required to ensure that this array does not get modified.

  17. trait S3d extends DbpfType
  18. trait Sc4Path extends DbpfType
  19. final class StreamedEntry extends DbpfEntry

    A lightweight entry that reads its data as stream from a file without holding all the data constantly in memory.

    A lightweight entry that reads its data as stream from a file without holding all the data constantly in memory.

    Usually, it is not necessary to load all the entries into memory, especially when processing large files, so instances of this class can be directly read from and written to files. Note that this is sensitive to changes of the source file: If the source file has been modified since this entry had been created, a DbpfStreamOutOfDateException will be thrown upon calling input so as to preclude malformed data.

    See also

    RawEntry

    BufferedEntry

  20. sealed trait Tgi extends LabeledTgi

    Represents Type, Group, Instance identifiers of DbpfEntries.

    Represents Type, Group, Instance identifiers of DbpfEntries. Tgi objects are immutable.

    Instances of this class may be obtained via the companion object's apply method, for example:

    val tgi = Tgi(0, 0, 0x12345678)

    Alternatively, the copy methods can be used to create modified copies.

    tgi.copy(iid = 0x87654321)
    tgi.copy(Tgi.Sc4Path)

    The matches method is used to test whether a Tgi matches another Tgi object or TgiMask.

  21. sealed trait TgiMask extends TgiLike

    Represents masks of TGIs that are used for the match method of Tgi.

    Represents masks of TGIs that are used for the match method of Tgi.

    Instances of this class may be obtained via the companion object's apply methods.

  22. trait WithContentConverter[B <: DbpfType] extends AnyRef

    This trait is used for companion objects of DbpfTypes and is needed in particular for Exemplars.

Value Members

  1. implicit def genericConverter[A <: DbpfType](implicit conv: Converter[DbpfType, A]): Converter[BufferedEntry[DbpfType], BufferedEntry[A]]

    provides a converter for BufferedEntries, given a converter of DbpfTypes

  2. implicit def noopConverter[A <: DbpfType]: Converter[BufferedEntry[A], BufferedEntry[A]]

    resolves generalizing conversions from specialized types to general ones

  3. val strategy: scdbpf.compat.strategy.type
  4. object DbpfExceptions
  5. object DbpfFile

    Provides factory methods for reading and writing DBPF files.

  6. object DbpfPackager

    Provides method for QFS compressing and decompressing.

  7. object DbpfProperty
  8. object DbpfUtil
  9. object Exemplar extends WithContentConverter[Exemplar]
  10. object Experimental

    Provides a few experimental functions that are useful, but which may still be changed in the future.

  11. object Fsh extends DbpfTypeCompanion[Fsh]
  12. object LText extends DbpfTypeCompanion[LText]
  13. object RawType
  14. object S3d extends DbpfTypeCompanion[S3d]
  15. object Sc4Path extends DbpfTypeCompanion[Sc4Path]
  16. object Tgi

    Provides various masks that Tgis can be matched against.

  17. object TgiMask

    Provides factory methods for creating TgiMasks.

Inherited from AnyRef

Inherited from Any

Ungrouped