local_fire_department TGPlug Developer Guide

TGMoLink Security Protocols
For TGMod v3-secure

⚠️ Why Your TGPlug Might Fail Validation

Here's what happened:

Your code had a race condition! 🏃‍♂️💨 It checked if TGMoLink existed, but didn't WAIT for registration to complete before running mod features. TGMoLink's security system is strict and will flag mods that try to execute logic before properly registering their TGUID.

The Problem Pattern:

// ❌ BAD - This causes race conditions! if (window.TGMoLink && window.TGMoLink.register) { window.TGMoLink.register(MOD_ID); } // Your code runs immediately - but registration might not be done! initializeModFeatures(); // 💥 Gatekeeper throws warning!

Why it validates "eventually": The registration DOES happen, but there's a timing gap where your mod starts before TGMoLink confirms the TGUID. TGMoLink hates that!

✅ The Correct Pattern (TGMoLink Compliant)

This is the ONLY way to ensure your mod passes TGMoLink's security checks:

(function() { 'use strict'; const MOD_ID = 'workshop.shaman.yourplug'; // Use your workshop ID! function startPlug() { if (window.TGMoLink && window.TGMoLink.register) { const success = window.TGMoLink.register(MOD_ID); if (success) { console.log(`[${MOD_ID}] Protocol Active. ⚡`); // Only run your mod logic AFTER successful registration initializeModFeatures(); } } else { // Wait silently without throwing errors setTimeout(startPlug, 100); } } function initializeModFeatures() { // Your beautiful code goes here! console.log('🎨 Mod features initialized!'); // Example: Announce yourself window.TGMoLink.broadcast('Mod is alive!', MOD_ID); } startPlug(); })();

🎯 Why This Works:

compare_arrows

Side-by-Side Comparison

cancel OLD WAY

if (window.TGMoLink) { window.TGMoLink.register(ID); } // Code runs immediately doStuff(); // 💥 Error!

Problems: No success verification, features run too early, Gatekeeper warnings.

check_circle NEW WAY

function start() { if (TGMoLink?.register) { if (TGMoLink.register(ID)) { doStuff(); // ✅ Safe! } } else setTimeout(start, 100); } start();

Benefits: Waits for API, Checks success, Passes gatekeeper.

code

Complete Working Example

Here's a FULL working TGPlug that passes all TGMoLink security checks.

main.js - Purple Theme Mod

// TGPlug: Shaman's Purple Dream // TGUID: workshop.shaman.purpledream // Version: 2.0 (Fixed) (function() { 'use strict'; const MOD_ID = 'workshop.shaman.purpledream'; const VERSION = '2.0'; // Master initialization function function startPlug() { // Check if TGMoLink exists and has register method if (window.TGMoLink && window.TGMoLink.register) { // Attempt registration const registered = window.TGMoLink.register(MOD_ID); if (registered) { console.log(`[${MOD_ID}] ⚡ Registration successful! Version ${VERSION}`); // NOW it's safe to run your mod features initializeTheme(); announcePresence(); setupEventListeners(); } else { console.error(`[${MOD_ID}] ❌ Registration failed - invalid TGUID?`); } } else { // TGMoLink not ready yet, wait and try again setTimeout(startPlug, 100); } } function initializeTheme() { console.log(`[${MOD_ID}] 🎨 Applying purple theme...`); // Mod logic here... } // START THE PLUG! startPlug(); })();

style.css - Visual Enhancements

/* TGPlug: Shaman's Purple Dream * TGUID: workshop.shaman.purpledream */ :root { --primary: #667eea !important; --accent: #764ba2 !important; } .toolbar { background: linear-gradient(135deg, rgba(102, 126, 234, 0.2), rgba(118, 75, 162, 0.2)) !important; backdrop-filter: blur(30px) !important; }
build

Troubleshooting Common Errors