g-man-tf2

module
v0.7.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: BSD-3-Clause

README ΒΆ

πŸŽ’ G-MAN TF2

The Ultimate Team Fortress 2 Domain Module & Economy Engine for G-MAN

Go Reference License GitHub Stars

"Professionals have standards"

πŸ‡ΊπŸ‡Έ English β€’ πŸ‡·πŸ‡Ί Русский

G-MAN TF2 is the official, production-grade Team Fortress 2 domain module and economy engine designed for the G-MAN automation framework. It bridges Valve's Game Coordinator (GC), real-time inventory caching, and complex TF2 trading math into a high-performance, decoupled Go package.

go get github.com/lemon4ksan/g-man-tf2@latest

πŸ“‚ Project Directory Structure

pkg/
β”œβ”€β”€ tf2/              # Central TF2 GC Session Driver & SOCache Cache
β”‚   β”œβ”€β”€ tf2.go        # Module implementation & options (RegisterModule)
β”‚   β”œβ”€β”€ socache.go    # Live GC Shared Object parser & inventory keeper
β”‚   └── actions.go    # Low-level GC commands (Crafting, Achievement Unlocking)
β”œβ”€β”€ backpack/         # Unified in-memory inventory views & slot lock management
β”œβ”€β”€ crafting/         # Automated crafting & weapon smelting engine recipes
β”œβ”€β”€ schema/           # High-fidelity TF2 schema manager & items_game parser
β”œβ”€β”€ sku/              # Standardized item SKU parsers (quality, effect, paint, etc.)
β”œβ”€β”€ currency/         # Float-safe metal arithmetic & Key-to-Scrap equations
β”œβ”€β”€ services/         # Third-party platform services integrations
β”‚   β”œβ”€β”€ pricedb/      # Pricing and PriceDB Socket.IO connection sync
β”‚   β”œβ”€β”€ bptf/         # backpack.tf integrations (listing management, snap scraper)
β”‚   β”œβ”€β”€ crit/         # Crit.tf storefront listing synchronizer
β”‚   β”œβ”€β”€ mannco/       # mann.co api integration and ws client 
β”‚   β”œβ”€β”€ express/      # express-load integration for community inventories
β”‚   └── rep/          # Trust, feedback, and user reputation lookup utilities
β”œβ”€β”€ trading/          # Onion-style trading middlewares (pricer, limits, counters)
β”œβ”€β”€ reason/           # TF2-specific trade rejection reasons

πŸš€ Quick Start

1. Install Dependencies

You need both the core G-MAN runtime client and the TF2 domain package:

go get github.com/lemon4ksan/g-man@latest
go get github.com/lemon4ksan/g-man-tf2@latest
2. Initialize the Orchestrator

Launch the client, register the TF2 schema and backpack managers, and load active trading middlewares:

package main

import (
	"context"
	"os"

	"github.com/lemon4ksan/g-man/pkg/log"
	"github.com/lemon4ksan/g-man/pkg/steam"
	"github.com/lemon4ksan/g-man/pkg/steam/auth"
	"github.com/lemon4ksan/g-man/pkg/steam/sys/apps"
	"github.com/lemon4ksan/g-man/pkg/steam/sys/directory"
	"github.com/lemon4ksan/g-man/pkg/steam/sys/gc"
	"github.com/lemon4ksan/g-man/pkg/storage/jsonfile"
	"github.com/lemon4ksan/g-man/pkg/trading/web"

	// G-MAN TF2 Imports
	"github.com/lemon4ksan/g-man-tf2/pkg/backpack"
	"github.com/lemon4ksan/g-man-tf2/pkg/schema"
	"github.com/lemon4ksan/g-man-tf2/pkg/tf2"
)

func main() {
	ctx := context.Background()
	store, _ := jsonfile.New("storage.json")
	logger := log.New(log.DefaultConfig(log.LevelInfo))

	// 1. Initialize Steam Client with modular G-MAN TF2 plugins
	client, err := steam.NewClient(steam.DefaultConfig(),
		steam.WithLogger(logger),
		steam.WithStorage(store),
		gc.WithModule(),
		apps.WithModule(),
		tf2.WithModule(),
		schema.WithModule(schema.DefaultConfig()),
		backpack.WithModule(),
		web.WithModule(web.DefaultConfig()),
	)
	if err != nil {
		panic(err)
	}
	defer client.Close()

	// 2. Fetch registered module references
	bpMod := backpack.From(client)

	// 3. Listen for inventory updates synced via GC SOCache
	sub := client.Bus().Subscribe(&tf2.BackpackLoadedEvent{})
	go func() {
		for event := range sub.C() {
			if bpEvent, ok := event.(*tf2.BackpackLoadedEvent); ok {
				logger.Info("TF2 Inventory synchronized via SOCache!",
					log.Int("items_count", bpEvent.Count),
				)

				pure := bpMod.GetPureStock()
				logger.Info("Current balances",
					log.Int("keys", pure.Keys),
					log.Float64("refined", pure.TotalRefined()),
				)
			}
		}
	}()

	if err := client.Run(); err != nil {
		panic(err)
	}

	// 4. Discover optimal connection server and login
	dir := directory.New(client)
	server, _ := dir.GetOptimalCMServer(ctx)
	login := auth.NewLogOnDetails(os.Getenv("STEAM_USER"), os.Getenv("STEAM_PASS"))

	if err := client.ConnectAndLogin(ctx, server, login); err != nil {
		panic(err)
	}

	client.Wait()
}
3. Register TF2 Onion-Trading Middlewares

Add decoupled processing steps to build your custom business rule checks inside G-MAN's Trade Offer Engine:

package main

import (
	"github.com/lemon4ksan/g-man/pkg/log"
	"github.com/lemon4ksan/g-man/pkg/trading/engine"

	"github.com/lemon4ksan/g-man-tf2/pkg/backpack"
	"github.com/lemon4ksan/g-man-tf2/pkg/schema"
	"github.com/lemon4ksan/g-man-tf2/pkg/services/pricedb"
	"github.com/lemon4ksan/g-man-tf2/pkg/trading"
)

func RegisterPipeline(
	tradeEngine *engine.Engine,
	bp *backpack.Backpack,
	priceMgr *pricedb.Manager,
	schemaMod *schema.Manager,
	logger log.Logger,
) {
	stockCfg := trading.StockConfig{
		MaxTotal:   3000,
		DefaultMax: 20,
		MaxPerSKU: map[string]int{
			"5021;6": 500, // Limit Mann Co. Supply Crate Keys to 500
		},
	}

	tradeEngine.Use(
		// 1. Stock checking middleware
		trading.StockLimitMiddleware(bp, stockCfg, logger),

		// 2. Price DB validation middleware
		trading.PricerMiddleware(priceMgr, schemaMod.Get, logger),
	)
}

⚑ Memory & Performance Efficiency

G-MAN TF2 inherits G-MAN’s core focus on low-footprint systems, making it highly suitable for running dozens of concurrent accounts on a single cheap VPS:

  • Fidelity Schema Engine: Prunes excess game tracker structures (especially in LiteMode), indexing item defindexes and schema attributes in a mere ~10 MB of active heap memory.
  • SOCache Storage: Employs zero-allocation pointer mappings to reflect inventories, keeping physical memory footprint at ~25 MB RSS overall under production workloads.

🀝 Contributing

We welcome contributions to G-MAN TF2! If you're interested in refining metal combining formulas, improving the dynamic schema deserializer, or enhancing reputation lookup APIs:

  1. Review CONTRIBUTING.md for conventions.
  2. Verify changes with unit tests: go test -race ./....
  3. Open a Pull Request detailing the changes and your design logic.

β˜• Support the Development

Testing Game Coordinator states, live trade offers, and smelting workflows requires active capital to cover Steam Market transaction fees, in-game item acquisitions, and test-transaction fees. If G-man helped you automate your trading workflows or optimized your server resources, feel free to show some support:

Trade Offer

"Yeah, money well spent!"

Disclaimer: This software is not affiliated with, maintained by, or endorsed by Valve Corporation or any of its subsidiaries. Steam, Team Fortress 2, and all related Valve properties are registered trademarks of Valve Corporation. Use of this library is at your own risk.

This project is licensed under the BSD 3-Clause License. See LICENSE for full details.

Directories ΒΆ

Path Synopsis
cmd
bot command
coverage command
examples
inventory command
maintenance command
internal
bytesconv
Package bytesconv provides zero-allocation byte slice and string manipulation utilities, optimized for Go compiler SSA passes, bounds check elimination (BCE), and SWAR execution.
Package bytesconv provides zero-allocation byte slice and string manipulation utilities, optimized for Go compiler SSA passes, bounds check elimination (BCE), and SWAR execution.
stringpool
Package stringpool implements thread-safe string interning across 64 shards to eliminate duplicate string allocations.
Package stringpool implements thread-safe string interning across 64 shards to eliminate duplicate string allocations.
pkg
backpack
Package backpack manages local inventory caching, item locking, stock calculation, and structural layout sorting for Team Fortress 2.
Package backpack manages local inventory caching, item locking, stock calculation, and structural layout sorting for Team Fortress 2.
behavior/pricemanager
Package pricemanager provides a backpack.tf price manager for the g-man-tf2 bot.
Package pricemanager provides a backpack.tf price manager for the g-man-tf2 bot.
crafting
Package crafting automates metal condensing, weapon smelting, and trade change balancing.
Package crafting automates metal condensing, weapon smelting, and trade change balancing.
currency
Package currency handles Team Fortress 2 monetary calculations, parsing, and formatting.
Package currency handles Team Fortress 2 monetary calculations, parsing, and formatting.
reason
Package reason contains TF2-specific trade decision reason codes.
Package reason contains TF2-specific trade decision reason codes.
schema
Package schema maintains and indexes Team Fortress 2 item definitions, qualities, attributes, and particle effects.
Package schema maintains and indexes Team Fortress 2 item definitions, qualities, attributes, and particle effects.
services/bptf
Package bptf implements a client for the backpack.tf API to manage classified listings and audit user reputations.
Package bptf implements a client for the backpack.tf API to manage classified listings and audit user reputations.
services/express
Package express provides a client for the Express Load API.
Package express provides a client for the Express Load API.
services/mannco
Package mannco provides the TF2 Mannco.store API client.
Package mannco provides the TF2 Mannco.store API client.
services/pricedb
Package pricedb implements a client for the PriceDB.io API to track TF2 item prices.
Package pricedb implements a client for the PriceDB.io API to track TF2 item prices.
services/rep
Package rep provides utilities for checking user bans against various ban lists.
Package rep provides utilities for checking user bans against various ban lists.
sku
Package sku provides zero-allocation parsing, generation, and validation for Team Fortress 2 Stock Keeping Unit (SKU) strings.
Package sku provides zero-allocation parsing, generation, and validation for Team Fortress 2 Stock Keeping Unit (SKU) strings.
tf2
Package tf2 integrates with the Team Fortress 2 Game Coordinator.
Package tf2 integrates with the Team Fortress 2 Game Coordinator.
trading
Package trading implements Team Fortress 2 automated trading, valuation, and security logic.
Package trading implements Team Fortress 2 automated trading, valuation, and security logic.

Jump to

Keyboard shortcuts

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