gameid

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package gameid works out what a game file is from its own bytes: which console it belongs to, whether it's a game at all, what it calls itself, and how sure that is.

A file's extension is only a hint, and on old formats a poor one: .bin and .iso mean half a dozen consoles, .md is usually a text file, .dmg a Mac disk image and .vb source code. So nothing here trusts one. Every check reads a few fixed places in the file, and says in plain words what it found, so that a person can see why.

Files are hostile until proven otherwise. Reads are small and bounded, sizes in a file are checked before they're used, and nothing is ever decrypted: an encrypted file is only recognised as one, from what its headers say in the open.

The package knows consoles only by their ids, and has no dependencies beyond the standard library, so anything can use it.

Index

Constants

View Source
const (
	Sega32X  = "32x"
	SegaCD   = "segacd"
	Saturn   = "saturn"
	GameCube = "gc"
	Wii      = "wii"
	WiiU     = "wiiu"
	PS3      = "ps3"
	Xbox     = "xbox"
	Switch   = "switch"
	ThreeDO  = "3do"
	PCFX     = "pcfx"
	NeoGeoCD = "neogeocd"
	CDI      = "cdi"
)

Consoles this package recognises that the server may not be able to play. They're still worth naming: "this is a Saturn disc" beats "this doesn't look like a game".

Variables

This section is empty.

Functions

func CheckFor

func CheckFor(console string, r io.ReaderAt, size int64) (fits bool, why string)

CheckFor is for consoles whose cartridges have no header at all. It can't prove a file is for one of these, only say whether a file a folder says is for one could be.

func DiscIn

func DiscIn(stem string) (disc, total int, rest string)

DiscIn reads which disc of how many a name says it is, and what's left of the name without that: "Mega Game (Disc 2 of 3)" is 2, 3 and "Mega Game". 0 when it doesn't say.

func IsSlug

func IsSlug(stem string) bool

IsSlug says a name was written for a web address, not a person: no spaces, and words joined by dashes.

func SerialIn

func SerialIn(name string) string

SerialIn finds a disc's product code in a name, written as databases write it.

func TrackNumber

func TrackNumber(stem string) int

TrackNumber says which track of a disc a name is, or 0.

func Unslug

func Unslug(stem string) string

Unslug makes a person's name of a web address's: final-fantasy-vii-u-scus-94163- is "final fantasy vii". What's taken off goes in the tags.

Types

type Finding

type Finding struct {
	// Console is the console the bytes prove, or "".
	Console string
	Kind    Kind
	// Proof says what was seen, in words for a person.
	Proof string
	// Title and Serial are what the file calls itself, Region where it says it's from.
	Title, Serial, Region string
	// Encrypted: this file's headers say it's encrypted, or its contents can't be read
	// the way they would be if they weren't. 3DS, Switch and Wii U files can be.
	Encrypted bool
	// NeedsKeys: it's encrypted, and that's how it's meant to be played. A standalone
	// emulator decrypts it with keys the owner copied from their own console, so it's a
	// game to list, not one that can't play. Only set along with Encrypted.
	NeedsKeys bool
	// NewOnly: a 3DS game that only runs on a New 3DS.
	NewOnly bool
	// Text: this is a text file, whatever it's called.
	Text bool
	// Media is what a compressed disc image says it holds: cd, dvd or gd.
	Media string
}

Finding is what a file's bytes say about it.

func Sniff

func Sniff(r io.ReaderAt, size int64) Finding

Sniff reads a file and says what it is. It costs a handful of small reads, plus one or two compressed blocks for a compressed disc.

func SniffFile

func SniffFile(path string) (Finding, error)

SniffFile opens a file and says what it is. A sheet is judged by what it names.

func SniffHead

func SniffHead(b []byte, size int64) Finding

SniffHead is Sniff for the first bytes of a file that can't be read at will, such as one inside an archive. What's past the end of b counts as not there, so size is what the file really is, not len(b).

func (Finding) Proven

func (f Finding) Proven() bool

Proven says the bytes settled which console this is for.

type Kind

type Kind string

Kind is what sort of thing a file is.

const (
	// KindUnknown: nothing here could say.
	KindUnknown Kind = ""
	// KindGame is something a person plays.
	KindGame Kind = "game"
	// KindBIOS is a console's or a copier's start-up software.
	KindBIOS Kind = "bios"
	// KindUpdate patches a game someone already has.
	KindUpdate Kind = "update"
	// KindDLC is extra content for a game.
	KindDLC Kind = "dlc"
	// KindUtility is a test cartridge, a cheat device, a menu: it runs, but isn't a game.
	KindUtility Kind = "utility"
	// KindAudio is a music CD, a chiptune, or one audio track of a disc.
	KindAudio Kind = "audio"
	// KindData is one piece of a game that can't stand alone.
	KindData Kind = "data"
	// KindOther is anything else: text, a PC program, a film disc.
	KindOther Kind = "other"
)

func ClassifyName

func ClassifyName(stem string) (Kind, string)

ClassifyName says what a file's name, without its extension, says it is. Most names say nothing: "" means it's left to the bytes.

type Quality

type Quality int

Quality is how good a copy a set's entry is, from what its name says.

const (
	QualityClean      Quality = iota // a plain dump of a released game
	QualityPrerelease                // beta, demo, sample
	QualityTranslated                // someone's translation
	QualityAltered                   // bad dump, overdump, trainer, fix
	QualityHack                      // someone's game built on this one
	QualityPD                        // homemade: demos, intros
)

From best to worst.

func QualityOf

func QualityOf(name string) Quality

QualityOf says what an entry's name says about it.

type Sheet

type Sheet struct {
	// Files are every file it names that's inside its own folder, in order.
	Files []string
	// Data is the file holding the first data track: what a console reads.
	Data string
	// AudioOnly: every track is audio, so it's a music CD.
	AudioOnly bool
	// Missing are the files it names that aren't there.
	Missing []string
}

Sheet is what one of these files lists.

func ParseSheet

func ParseSheet(ext, name string, in io.Reader, dir string, exists func(string) bool) (*Sheet, error)

ParseSheet does the work of ReadSheet for a sheet from anywhere. exists says whether a file is there, given dir joined with what the sheet says.

func ReadSheet

func ReadSheet(path string) (*Sheet, error)

ReadSheet reads a .cue, .gdi, .ccd, .toc or .m3u. It reads at most 1 MB and 2,000 lines. A .ccd names nothing: its image is the .img beside it.

Directories

Path Synopsis
Package fixture makes tiny files for tests that have the headers real games have and nothing else: no game's code or data, only the marks the checks in gameid look for.
Package fixture makes tiny files for tests that have the headers real games have and nothing else: no game's code or data, only the marks the checks in gameid look for.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL