gma

package module
v0.0.0-...-2617543 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 8 Imported by: 0

README

GMA Reader

Work with .gma (Garry's Mod Addon) files from withing your GoLang application.

Features
  • Read meta data from a .gma file, including
    • SteamID (author)
    • Timestamp
    • Name
    • Description
    • Type
    • Tags
    • Files
  • Extract the addon to a destination folder using concurrent reads and writes for maximum speed
Installation

go get -u github.com/ips-hosting/gma

Usage
package mypackage

import (
  "os"
  "path/filepath"
  "github.com/ips-hosting/gma"
)

func main() {
  // Open reader to a GMA file
  f, err := os.Open("12345.gma")
  defer f.Close()
  if err != nil {
    // Handle error
  }
  
  // Read gma file
  r := gma.NewReader(f)
  addon, err := r.ReadAddon()
  if err != nil {
    // Handle error
  }
  
  // Access information about addon
  // addon.Name
  // addon.Description
  // addon.Files
  // ...
  
  // Extract content of addon to destination
  dest := filepath.Join(os.TempDir(), "myaddon")
  err = addon.Extract(dest)
  if err != nil {
    // Handle error
  }
}
Credits

Official gmad utility by Facepunch

Documentation

Index

Constants

View Source
const (
	Ident   = "GMAD"
	Version = 3
)
View Source
const (
	AddonTypeGamemode      AddonType = "gamemode"
	AddonTypeMap                     = "map"
	AddonTypeWeapon                  = "weapon"
	AddonTypeVehicle                 = "vehicle"
	AddonTypeNPC                     = "npc"
	AddonTypeEntity                  = "entity"
	AddonTypeTool                    = "tool"
	AddonTypeEffects                 = "effects"
	AddonTypeModel                   = "model"
	AddonTypeServerContent           = "servercontent"
)
View Source
const (
	AddonTagFun      = "fun"
	AddonTagRoleplay = "roleplay"
	AddonTagScenic   = "scenic"
	AddonTagMovie    = "movie"
	AddonTagRealism  = "realism"
	AddonTagCartoon  = "cartoon"
	AddonTagWater    = "water"
	AddonTagComic    = "comic"
	AddonTagBuild    = "build"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Addon

type Addon struct {
	Src             Source
	FileBlockOffset int64

	// FormatVersion is the version of the GMA file
	FormatVersion byte
	// SteamID is the 64-bit Steam ID of the author
	SteamID uint64
	// Timestamp is the last time the addon has been updated
	Timestamp       uint64
	RequiredContent string
	Name            string
	Description     string
	Type            AddonType
	Tags            []AddonTag
	Author          string
	Version         int32
	Files           []AddonFileEntry
}

func (*Addon) Extract

func (a *Addon) Extract(dest string) error

Extract extracts the addon to the given destination directory

type AddonFileEntry

type AddonFileEntry struct {
	ID     uint32
	Name   string
	Size   uint64
	CRC    uint32
	Offset uint64
}

type AddonTag

type AddonTag string

type AddonType

type AddonType string

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func NewReader

func NewReader(src Source) *Reader

func (*Reader) ReadAddon

func (r *Reader) ReadAddon() (*Addon, error)

ReadAddon tries to read an addon from the source.

type Source

type Source interface {
	io.Reader
	io.Seeker
	io.ReaderAt
}

Jump to

Keyboard shortcuts

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