Redned235 / SimReader

A Java reader for game data from the Sim* Franchise.
MIT License
2 stars 0 forks source link
game java sc4 sim-city simcity simcity4 sims

SimReader

A Java parser for game data from the Sim* Franchise.

At the moment, this project only supports SimCity 4, but since many other Maxis games also use a similar format, it could be expanded to support those games too.

There are likely things missing, so pull requests are certainly welcome!

Usage

You can parse a .sc4 Savegame file by doing the following:

SC4File file = new SC4File(Paths.get("my_city.sc4"));

Often, SimCity 4 stores much of its data inside of Exemplar files, found inside the game directory (usually with file extension .dat). Lots of data stored inside Savegame files make references to this data in these Exemplars through it's PersistentResourceKey.

Here is an example that prints the name of each building:

SC4File file = new SC4File(Paths.get("my_city.sc4"));
ExemplarFile exemplarFile = new ExemplarFile(Paths.get("exemplar/SimCity_1.dat"));

for (Building building : file.getBuildingFile().getBuildings()) {
    IndexEntry indexEntry = exemplarFile.getEntry(building.getResourceKey());
    byte[] bytes = exemplarFile.getBytesAtIndex(indexEntry);

    ExemplarSubfile exemplar = ExemplarSubfile.parse(ExemplarSubfile::new, new FileBuffer(bytes));
    System.out.println("Building name: " + exemplar.getProperty(ExemplarPropertyTypes.EXEMPLAR_NAME).getValue());
}

Note: This project may have issues reading data from files generated by the SimCity 4 macOS port. While efforts have been made to support the encoding differences where possible, none of these differences are documented so while the data may parse in some cases, it may be jumbled. Please open an issue if you notice any problems!

Repository

Gradle

repositories {
    maven("https://jitpack.io")
}

dependencies {
    implementation("com.github.Redned235:SimReader:master-SNAPSHOT")
}

Maven:

<repositories>
    <repository>
        <id>jitpack</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.github.Redned235</groupId>
        <artifactId>SimReader</artifactId>
        <version>master-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

Credits

Much of this project would not be possible without the following resources & repositories: