use App\Beat\Encoder;
use App\Models\AosSeed;
-use HeadlessChromium\BrowserFactory;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
+use Symfony\Component\Process\Process;
class GenerateAosSeed extends Command
{
$temp_dir = sys_get_temp_dir();
$params = array_merge(['seed' => $seed->seed], $seed->settings);
- $url = config('aos.surge_url').'/?'.http_build_query($params, '', '&');
+ $settings = http_build_query($params, '', '&');
- $fac = new BrowserFactory('chromium');
- $fac->addOptions(['noSandbox' => true]);
- $browser = $fac->createBrowser();
-
- $stage = 'loading page';
- $page = $browser->createPage();
- $page->setDownloadPath($temp_dir);
- $page->navigate($url)->waitForNavigation();
-
- $stage = 'selecting rom';
- $fileInput = $page->dom()->querySelector('input[type=file]');
- $fileInput->sendFile(config('aos.base_rom'));
- $page->waitUntilContainsElement('select');
-
- $stage = 'clicking randomize';
- $page->mouse()->find('button', 2)->click();
- $page->waitUntilContainsElement('a[download]');
-
- $stage = 'clicking download';
- $page->dom()->querySelector('a[download]')->setAttributeValue('download', $seed->hash.'.gba');
- $page->mouse()->find('a[download]')->click();
-
- $stage = 'waiting for rom';
$romFile = $temp_dir.'/'.$seed->hash.'.gba';
- for ($i = 0; $i < 100; ++$i) {
- clearstatcache();
- if (is_file($romFile) && filesize($romFile) >= 8388608) {
- break;
- }
- usleep(100_000);
- }
+ $spoilerFile = $temp_dir.'/'.$seed->hash.'.txt';
+
+ $stage = 'randomizing';
+ $proc = new Process([config('aos.cli'), config('aos.base_rom'), $romFile, $settings]);
+ $proc->mustRun();
$stage = 'calculating patch';
$encoder = new Encoder(file_get_contents(config('aos.base_rom')));
Storage::disk('aos-seeds')->put($seed->hash.'.bps', $patch);
unlink($romFile);
+ $stage = 'saving spoiler';
+ Storage::disk('aos-spoilers')->put($seed->hash.'.txt', $proc->getOutput());
+
$stage = 'done';
$seed->status = 'generated';
$seed->save();
-
- $browser->close();
} catch (\Throwable $e) {
$seed->status = 'error';
$seed->error_detail = [
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "6782a76fb7c2451b20cb57f93be704df",
+ "content-hash": "a370e7a3f5ba178c836caec3a7ac4879",
"packages": [
{
"name": "beyondcode/laravel-websockets",
},
"time": "2021-12-14T00:20:41+00:00"
},
- {
- "name": "chrome-php/chrome",
- "version": "v1.6.0",
- "source": {
- "type": "git",
- "url": "https://github.com/chrome-php/chrome.git",
- "reference": "e8264cb33a02053caf8877c1566e54f09c60d10c"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/chrome-php/chrome/zipball/e8264cb33a02053caf8877c1566e54f09c60d10c",
- "reference": "e8264cb33a02053caf8877c1566e54f09c60d10c",
- "shasum": ""
- },
- "require": {
- "chrome-php/wrench": "^1.2",
- "evenement/evenement": "^3.0.1",
- "monolog/monolog": "^1.26 || ^2.2",
- "php": "^7.3 || ^8.0",
- "psr/log": "^1.1 || ^2.0 || ^3.0",
- "symfony/filesystem": "^4.4 || ^5.0 || ^6.0",
- "symfony/polyfill-mbstring": "^1.23",
- "symfony/process": "^4.4 || ^5.0 || ^6.0"
- },
- "require-dev": {
- "bamarni/composer-bin-plugin": "^1.4.1",
- "phpunit/phpunit": "^9.5.10",
- "symfony/var-dumper": "^4.4 || ^5.0 || ^6.0"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "HeadlessChromium\\": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Graham Campbell",
- "email": "hello@gjcampbell.co.uk",
- "homepage": "https://github.com/GrahamCampbell"
- },
- {
- "name": "Enrico Dias",
- "email": "enricodias@gmail.com",
- "homepage": "https://github.com/enricodias"
- }
- ],
- "description": "Instrument headless chrome/chromium instances from PHP",
- "keywords": [
- "browser",
- "chrome",
- "chromium",
- "crawl",
- "headless",
- "pdf",
- "puppeteer",
- "screenshot"
- ],
- "support": {
- "issues": "https://github.com/chrome-php/chrome/issues",
- "source": "https://github.com/chrome-php/chrome/tree/v1.6.0"
- },
- "time": "2022-03-30T09:50:16+00:00"
- },
- {
- "name": "chrome-php/wrench",
- "version": "v1.2.0",
- "source": {
- "type": "git",
- "url": "https://github.com/chrome-php/wrench.git",
- "reference": "e8a34b54df8c9cd4f6d166bdb9df475988e17ce4"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/chrome-php/wrench/zipball/e8a34b54df8c9cd4f6d166bdb9df475988e17ce4",
- "reference": "e8a34b54df8c9cd4f6d166bdb9df475988e17ce4",
- "shasum": ""
- },
- "require": {
- "ext-sockets": "*",
- "php": "^7.3 || ^8.0",
- "psr/log": "^1.1 || ^2.0 || ^3.0",
- "symfony/polyfill-php80": "^1.22"
- },
- "conflict": {
- "wrench/wrench": "*"
- },
- "require-dev": {
- "bamarni/composer-bin-plugin": "^1.4.1",
- "phpunit/phpunit": "^9.5.5"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "Wrench\\": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Graham Campbell",
- "email": "hello@gjcampbell.co.uk",
- "homepage": "https://github.com/GrahamCampbell"
- }
- ],
- "description": "A simple PHP WebSocket implementation",
- "keywords": [
- "WebSockets",
- "hybi",
- "websocket"
- ],
- "support": {
- "issues": "https://github.com/chrome-php/wrench/issues",
- "source": "https://github.com/chrome-php/wrench/tree/v1.2.0"
- },
- "time": "2022-03-30T09:35:45+00:00"
- },
{
"name": "dflydev/dot-access-data",
"version": "v3.0.1",
],
"time": "2022-01-02T09:55:41+00:00"
},
- {
- "name": "symfony/filesystem",
- "version": "v6.0.7",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/filesystem.git",
- "reference": "6c9e4c41f2c51dfde3db298594ed9cba55dbf5ff"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/filesystem/zipball/6c9e4c41f2c51dfde3db298594ed9cba55dbf5ff",
- "reference": "6c9e4c41f2c51dfde3db298594ed9cba55dbf5ff",
- "shasum": ""
- },
- "require": {
- "php": ">=8.0.2",
- "symfony/polyfill-ctype": "~1.8",
- "symfony/polyfill-mbstring": "~1.8"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "Symfony\\Component\\Filesystem\\": ""
- },
- "exclude-from-classmap": [
- "/Tests/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Provides basic utilities for the filesystem",
- "homepage": "https://symfony.com",
- "support": {
- "source": "https://github.com/symfony/filesystem/tree/v6.0.7"
- },
- "funding": [
- {
- "url": "https://symfony.com/sponsor",
- "type": "custom"
- },
- {
- "url": "https://github.com/fabpot",
- "type": "github"
- },
- {
- "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
- "type": "tidelift"
- }
- ],
- "time": "2022-04-01T12:54:51+00:00"
- },
{
"name": "symfony/finder",
"version": "v6.0.8",