michyaraque / g-php
G-Earth Extension for PHP
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/michyaraque/g-php
Requires
- php: ^8.4
- ext-sockets: *
This package is auto-updated.
Last update: 2025-11-26 14:56:29 UTC
README
PHP extension API for the Habbo packet interceptor G-Earth.
Requirements
- PHP 8.4+
ext-socketsenabled
Installation
composer require michyaraque/g-php
Usage
Getting Started
Create a new PHP script (e.g., extension.php):
<?php require_once 'src/G.php'; // or vendor/autoload.php use GPHP\Extension\{Extension, ExtensionInfo, HostInfo}; use GPHP\Protocol\{HMessage, HPacket}; use GPHP\Packets\Outgoing; use GPHP\Packets\Incoming; $extInfo = new ExtensionInfo( title: "My Extension", description: "A cool PHP extension", version: "1.0", author: "You" ); $ext = new Extension($extInfo); $ext->onConnect(function (HostInfo $hostInfo) { echo "Connected to " . $hostInfo->host . "\n"; }); $ext->run();
How to run
php extension.php
Intercepting Packets
You can intercept packets using the generated Incoming and Outgoing Enums.
$ext->intercept(Incoming::Chat, function (HMessage $msg) { $packet = $msg->getPacket(); $text = $packet->readString(); echo "User said: $text\n"; });
Sending Packets
Create an HPacket using the Enum and send it. The extension automatically detects the destination.
$packet = new HPacket(Outgoing::Chat); $packet->appendString("Hello World!"); $packet->appendInt(0); $packet->appendInt(-1); $ext->sendPacket($packet);
Reading & Writing Data
// Reading $val = $packet->readInt(); $str = $packet->readString(); [$x, $y] = $packet->read('ii'); // Writing $packet->appendInt(123); $packet->appendString("foo"); $packet->appendBool(true);
Background Tasks (Scheduler)
Use the Scheduler to run tasks without blocking packet processing.
use GPHP\Util\Scheduler; Scheduler::run(function() use ($ext) { for ($i = 0; $i < 10; $i++) { // Send a packet $ext->sendPacket(new HPacket(Outgoing::AvatarExpression)->appendInt(1)); // Wait 1 second (non-blocking) $start = microtime(true); while (microtime(true) - $start < 1.0) { \Fiber::suspend(); } } });
Packet Definitions
Packet definitions (Enums) are automatically generated in src/Packets.php when the extension connects to G-Earth for the first time. This provides Intellisense support in your IDE.
Running with Docker (Sandboxed)
You can run the extension inside a Docker container while still communicating with G-Earth.
- Ensure Docker and Docker Compose are installed.
- Run the extension:
docker-compose up --build
This uses host.docker.internal to connect to G-Earth running on your main OS.