From: Daniel Karbach Date: Wed, 25 May 2022 17:06:01 +0000 (+0200) Subject: faster implementation for generating AoSR seeds X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=e0195b0aebf84bdf5a05c887abc4300a6546a9b2;p=alttp.git faster implementation for generating AoSR seeds --- diff --git a/.env.example b/.env.example index 8105545..f5fea82 100644 --- a/.env.example +++ b/.env.example @@ -65,6 +65,7 @@ ALTTP_BASE_ROM= ALTTP_DOORS_CLI= AOS_BASE_ROM= +AOS_CLI= AOS_HOSTNAME=aos.localhorst.tv AOS_SURGE_URL=https://aosrando.surge.sh AOS_URL=https://aos.localhorst.tv diff --git a/app/Console/Commands/GenerateAosSeed.php b/app/Console/Commands/GenerateAosSeed.php index c51ce29..fa390c8 100644 --- a/app/Console/Commands/GenerateAosSeed.php +++ b/app/Console/Commands/GenerateAosSeed.php @@ -4,9 +4,9 @@ namespace App\Console\Commands; 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 { @@ -41,39 +41,14 @@ 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'))); @@ -81,11 +56,12 @@ class GenerateAosSeed extends Command 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 = [ diff --git a/composer.json b/composer.json index 20611d7..3c7d625 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,6 @@ "require": { "php": "^8.0.2", "beyondcode/laravel-websockets": "^1.13", - "chrome-php/chrome": "^1.6", "doctrine/dbal": "^3.3", "guzzlehttp/guzzle": "^7.2", "jakyeru/larascord": "^3.0", diff --git a/composer.lock b/composer.lock index 1ba6b8e..2a90da2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "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", @@ -211,130 +211,6 @@ }, "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", @@ -5610,69 +5486,6 @@ ], "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", diff --git a/config/aos.php b/config/aos.php index b6eaf2a..450524d 100644 --- a/config/aos.php +++ b/config/aos.php @@ -2,6 +2,7 @@ return [ 'base_rom' => env('AOS_BASE_ROM', ''), + 'cli' => env('AOS_CLI', ''), 'hostname' => env('AOS_HOSTNAME', 'aos.localhorst.tv'), 'surge_url' => env('AOS_SURGE_URL', 'https://aosrando.surge.sh'), 'url' => env('AOS_URL', 'https://aos.localhorst.tv'), diff --git a/config/filesystems.php b/config/filesystems.php index e743e9f..4076fb5 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -63,6 +63,11 @@ return [ 'visibility' => 'public', ], + 'aos-spoilers' => [ + 'driver' => 'local', + 'root' => storage_path('app/aos-spoilers'), + ], + 's3' => [ 'driver' => 's3', 'key' => env('AWS_ACCESS_KEY_ID'),