g-man-tf2

module
v0.1.1 Latest Latest
Warning

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

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

README ΒΆ

πŸŽ’ G-MAN TF2

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

Go Reference Go Report Card 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

⚑ Core Ecosystem Capabilities

πŸͺ™ 1. Advanced Currency & Pricing Mechanics (tf2/currency)

Trading TF2 items demands zero-tolerance precision in Keys and Refined Metal.

  • Float-Safe Metal Arithmetic: G-MAN TF2 handles all currency by internally converting metal units to base-level integers (Scrap), guaranteeing exact results (e.g., AddRefined(1.55, 0.55) returns exactly 2.11 without precision drift).
  • Separate Key Rates: Evaluates keys dynamically depending on trade direction (buy rate when receiving keys, sell rate when giving keys) to maximize arbitrage profit margin.
  • Weapon as Currency: Seamlessly integrates weapons (0.05 refined) into the base metal arithmetic, facilitating precise micro-transactions and change.
πŸŽ’ 2. Real-Time Inventory & Storage Optimization (tf2/backpack, tf2/crafting)

Avoid heavy rate-limits from web inventory requests and keep storage organized.

  • GC SOCache Synchronization: Stays synced with the active SOCache (Shared Object Cache) in the Game Coordinator's memory space. Binary GC packets are parsed in O(1) time to patch the local inventory view instantly.
  • Backpack Auto-Sorting: Automatically packs and groups items cleanly (pure currency first, weapons, cosmetics, or custom page categories) using sequential SetSingleItemPosition Game Coordinator updates.
  • Smart Trash Cleanup: Automatically scans and permanently purges untradable junk items (empty crates/cases, noise makers, seasonal holiday garbage) to prevent backpack overflow and trading halts.
  • Smelting & Crafting Engine: Automatically constructs recipes, combines metal units (Scrap $\leftrightarrow$ Reclaimed $\leftrightarrow$ Refined), and melts duplicate weapons to manage storage dynamically and resolve exact change requirements.
πŸ“ˆ 3. PriceDB & Premium Item Valuation (tf2/pricedb)

Retrieve and sync asset values without spamming HTTP request limits and capture premium item value.

  • Real-Time PriceDB Sync: Streams live pricing changes directly from the PriceDB service using a persistent Socket.IO connection.
  • Premium Painted Items Valuation: Automatically calculates added premiums for custom-painted weapons and gear.
  • Halloween Spells Premium Valuation: Recognizes spelled items (Pumpkin Bombs, Exorcism, footprints, vocal) and layers customizable pricing premiums above base rates dynamically.
πŸ§… 4. Onion-Trading Middlewares & Anti-Ghost Listings (tf2/trading)

Secure your reputation and transactions with a decoupled onion-style middleware engine.

  • Anti-Ghost Listings Filter: Prevents posting listings on backpack.tf for buy orders if the bot doesn't have enough pure currency to fulfill them, preventing negative community reputation.
  • Smart Countering & Change Maker: Automatically counters imbalanced offers with exact change using the smelting engine.
πŸ“Š 5. Trade Accounting & Analytics Subsystem (tf2/stats)

Monitor your business performance with real-time financial ledger tracking.

  • FIFO Profit Accounting Ledger: Calculates exact transaction profits in refined/keys and maintains active cost bases dynamically.
πŸ€– 6. Automation & Safety Systems
  • Auto-Reset Manual Prices: Re-evaluates manually priced items once they sell out, resetting them automatically to dynamic autotrading rates.
  • Auto-Cancel Stale Sent Offers: Automatically cancels sent offers pending too long (e.g. 15 minutes) to unlock locked items and avoid trade overrides.

πŸ“‚ 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/      # Local pricing store adapters and PriceDB Socket.IO connection sync
β”‚   β”œβ”€β”€ bptf/         # backpack.tf integrations (listing management, snap scraper)
β”‚   β”œβ”€β”€ crit/         # Crit.tf storefront listing synchronizer
β”‚   └── rep/          # Trust, feedback, and user reputation lookup utilities
β”œβ”€β”€ behavior/         # High-level behavior loops (autokeys, stock manager, syncers)
β”œβ”€β”€ trading/          # Onion-style trading middlewares (pricer, limits, counters)
β”œβ”€β”€ ecp/              # Escrow Bypass Chat Protocol (Obfuscator & Compressor)
β”œβ”€β”€ reason/           # TF2-specific trade rejection reasons
└── storage/          # Local JSON file & cache adapters

πŸš€ 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/directory"
	"github.com/lemon4ksan/g-man/pkg/storage/jsonfile"
	
	// 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.Config{Storage: store},
		steam.WithLogger(logger),
		tf2.WithModule(),
		schema.WithModule(schema.DefaultConfig()),
		backpack.WithModule(),
	)
	if err != nil {
		panic(err)
	}
	defer client.Close()

	// 2. Fetch registered module references
	tf2Mod := tf2.From(client)
	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()),
				)
			}
		}
	}()

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

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

	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/pricedb"
	"github.com/lemon4ksan/g-man-tf2/pkg/trading"
)

func RegisterPipeline(
	tradeEngine *engine.Engine,
	bp *backpack.Backpack,
	priceMgr *pricedb.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, 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
pkg
backpack
Package backpack manages the Team Fortress 2 inventory state for both local and remote profiles.
Package backpack manages the Team Fortress 2 inventory state for both local and remote profiles.
behavior/autokeys
Package autokeys provides automatic key trading and scrap metal balancing.
Package autokeys provides automatic key trading and scrap metal balancing.
behavior/critlistener
Package critlistener listens for crit.tf events and processes them.
Package critlistener listens for crit.tf events and processes them.
behavior/listingsync
Package listingsync provides automated reactive classified listings synchronization with backpack.tf and crit.tf based on inventory and price updates.
Package listingsync provides automated reactive classified listings synchronization with backpack.tf and crit.tf based on inventory and price updates.
behavior/pricelistsaver
Package pricelistsaver provides a high-performance background writer that persisting pricedb updates to local pricelist JSON files with robust debouncing.
Package pricelistsaver provides a high-performance background writer that persisting pricedb updates to local pricelist JSON files with robust debouncing.
behavior/staleoffers
Package staleoffers provides automatic cancellation of outbound trade offers that have remained active/pending for longer than a specified duration.
Package staleoffers provides automatic cancellation of outbound trade offers that have remained active/pending for longer than a specified duration.
behavior/stock
Package stock provides automated watchlist seeding, dynamic FIFO stagnant stock discounting, and crafting coordination.
Package stock provides automated watchlist seeding, dynamic FIFO stagnant stock discounting, and crafting coordination.
crafting
Package crafting provides automatic crafting, metal condensing, and metal-change operations for Team Fortress 2.
Package crafting provides automatic crafting, metal condensing, and metal-change operations for Team Fortress 2.
currency
Package currency provides high-performance structures and utilities for Team Fortress 2 currency math.
Package currency provides high-performance structures and utilities for Team Fortress 2 currency math.
ecp
Package ecp implements the Easy-Copy-Paste (ECP) format for Team Fortress 2 items.
Package ecp implements the Easy-Copy-Paste (ECP) format for Team Fortress 2 items.
pricing
Package pricing provides centralized domain types for TF2 item valuation source tracking.
Package pricing provides centralized domain types for TF2 item valuation source tracking.
reason
Package reason contains TF2-specific trade reasons.
Package reason contains TF2-specific trade reasons.
schema
Package schema provides a manager for the Team Fortress 2 item schema.
Package schema provides a manager for the Team Fortress 2 item schema.
services/bptf
Package bptf provides a comprehensive, high-performance Go client for the backpack.tf API, specifically designed for Team Fortress 2 trading automation.
Package bptf provides a comprehensive, high-performance Go client for the backpack.tf API, specifically designed for Team Fortress 2 trading automation.
services/crit
Package crit provides an integration client for crit.tf classifieds, group stores and showcase APIs.
Package crit provides an integration client for crit.tf classifieds, group stores and showcase APIs.
services/manualprices
Package manualprices provides a service for managing manual buy/sell prices.
Package manualprices provides a service for managing manual buy/sell prices.
services/pricedb
Package pricedb provides a high-performance, strictly typed client for the PriceDB.io API.
Package pricedb provides a high-performance, strictly typed client for the PriceDB.io API.
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 implements the TF2 Stock Keeping Unit format.
Package sku implements the TF2 Stock Keeping Unit format.
storage
Package storage provides interfaces and implementations for persisting tf2 logic state.
Package storage provides interfaces and implementations for persisting tf2 logic state.
storage/jsonfile
Package jsonfile provides a JSON-based implementation of the CostBasisStore interface.
Package jsonfile provides a JSON-based implementation of the CostBasisStore interface.
tf2
Package tf2 provides integration with the Team Fortress 2 Game Coordinator.
Package tf2 provides integration with the Team Fortress 2 Game Coordinator.
trading
Package trading defines the Team Fortress 2 automated trading, valuation, and security logic.
Package trading defines the Team Fortress 2 automated trading, valuation, and security logic.
trading/stats
Package stats provides high-level APIs to calculate and analyze trade profitability.
Package stats provides high-level APIs to calculate and analyze trade profitability.

Jump to

Keyboard shortcuts

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