npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@camoto/gamecode

v2.0.0

Published

Modify executable files used by DOS games

Downloads

19

Readme

gamecode.js

Copyright 2010-2021 Adam Nielsen <[email protected]>

This is a Javascript library that can modify executable files for a number of MS-DOS games from the 1990s. It allows simple changes like modifying the text displayed in the user interface, to more complex changes like patching the code itself at runtime to change the game's behaviour.

Note that the library is still in the very early stages of development, so most of this functionality has not yet been implemented!

Some game executables have large data chunks. This library's focus is on small bits of data and so it does not provide access to those large chunks. Instead, those are accessible through gamearchive.js as an archive file.

Game support

The library currently supports these games:

  • Cosmo's Cosmic Adventure (episode 1)
  • Dangerous Dave
  • Nomad

Eventually, the patching functionality will work on any .exe file, specific game support is only needed for things like changing the text messages hard-coded into the game.

Installation as an end-user

If you wish to use the command-line gamecode utility to work with game executables directly, you can install the CLI globally on your system:

npm install -g @camoto/gamecode-cli

For Arch Linux users the AUR package gamecode-cli is also available.

Command line interface

The gamecode utility can be used to manipulate executable files. Commands are specified one after the other as parameters. Use the --help option to get a list of all the available commands. Some quick examples:

# List available text strings that can be edited
gamecode open cosmo1.exe list

# Change a text string
gamecode open cosmo1.exe set filenames.music.1 mysong.mni save cosmo1-new.exe

# Build a run-time patch file from the differences between the new and
# original file, so the original can be patched in-memory at run-time.
gamecode open cosmo1-new.exe diff cosmo1.exe mycosmo.exe

To get a list of supported file formats, run:

gamecode --formats

Installation as a dependency

If you wish to make use of the library in your own project, install it in the usual way:

npm install @camoto/gamecode

See cli/index.js for example use. The quick start is:

import {
    all as gamecodeFormats,
    decompressEXE,
    exe_cosmo1 as formatHandler,
} from '@camoto/gamecode';

// Read an executable's attributes into memory.
const content = {
    // Load the file and UNLZEXE it if needed.
    main: decompressEXE(fs.readFileSync('cosmo1.exe')),
    // Some formats need additional files here, see handler.supps()
};
let exe = formatHandler.extract(content);

// List the attributes.
console.log(exe.attributes);

// Change an attribute.
exe.attributes['filename.music.1'].value = 'newsong.mni';

// Write the .exe back to disk with the modifications.
const outBuffer = formatHandler.patch(content, exe);
fs.writeFileSync('cosmo1a.exe', outBuffer.main);

Installation as a contributor

If you would like to help add more file formats to the library, great! Clone the repo, and to get started:

npm install

Run the tests to make sure everything worked:

npm test

You're ready to go! To add a new file format:

  1. Create a new file in the formats/ folder for your format. Copying an existing file that covers a similar format will help considerably.

  2. Edit formats/index.js and add an import statement for your new file.

If your file format has any sort of compression or encryption, these algorithms should go into the gamecomp.js project instead. This is to make it easier to reuse the algorithms, as many of them (particularly the compression ones) are used amongst many unrelated file formats. All the gamecomp.js algorithms are available to be used by any format in this library.

During development you can test your code like this:

# Read a sample song and list its details, with debug messages on
$ DEBUG='gamecode:*' ./bin/gamecode open -t exe-myformat example.exe list

# Make sure the format is identified correctly or if not why not
$ DEBUG='gamecode:*' ./bin/gamecode identify example.exe

If you use debug() rather than console.log() in your code then these messages can be left in for future diagnosis as they will only appear when the DEBUG environment variable is set correctly.