From: Daniel Karbach Date: Wed, 18 May 2022 11:53:08 +0000 (+0200) Subject: add ALttP seed generator X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=4aeaa2ab482a0915da0016fc8175e7cbaa0ab261;p=alttp.git add ALttP seed generator --- diff --git a/.env.example b/.env.example index 3811845..8105545 100644 --- a/.env.example +++ b/.env.example @@ -61,6 +61,9 @@ DISCORD_BOT_TOKEN= DISCORD_BOT_CREATE_COMMANDS= DISCORD_BOT_ENABLE_COMMANDS= +ALTTP_BASE_ROM= +ALTTP_DOORS_CLI= + AOS_BASE_ROM= AOS_HOSTNAME=aos.localhorst.tv AOS_SURGE_URL=https://aosrando.surge.sh diff --git a/app/Console/Commands/GenerateAlttpSeed.php b/app/Console/Commands/GenerateAlttpSeed.php new file mode 100644 index 0000000..466f2f2 --- /dev/null +++ b/app/Console/Commands/GenerateAlttpSeed.php @@ -0,0 +1,98 @@ +argument('id')); + $seed->status = 'generating'; + $seed->error_detail = null; + $seed->save(); + + $temp_dir = sys_get_temp_dir(); + $rom_file = $temp_dir.'/DR_'.$seed->hash.'.sfc'; + $settings_file = $temp_dir.'/'.$seed->hash.'.json'; + $spoiler_file = $temp_dir.'/DR_'.$seed->hash.'_Spoiler.txt'; + + $stage = 'initial'; + try { + + $stage = 'settings'; + $settings = array_merge([ + 'calc_playthrough' => true, + 'create_rom' => true, + 'create_spoiler' => true, + 'count' => 1, + 'enemizercli' => base_path().'/vendor/z3/enemizer_linux/EnemizerCLI.Core', + 'multi' => 1, + 'names' => '', + 'outputpath' => $temp_dir, + 'outputname' => $seed->hash, + 'race' => $seed->race, + 'rom' => config('alttp.base_rom'), + 'seed' => $seed->seed, + ], $seed->settings); + file_put_contents($settings_file, json_encode($settings)); + + $stage = 'generate'; + $proc = new Process([config('alttp.doors_cli'), '--settingsfile', $settings_file]); + $proc->setWorkingDirectory(dirname(config('alttp.doors_cli'))); + $proc->mustRun(); + + $stage = 'calculating patch'; + $encoder = new Encoder(file_get_contents(config('alttp.base_rom'))); + $patch = $encoder->createPatch(file_get_contents($rom_file)); + $spoiler = file_get_contents($spoiler_file); + Storage::disk('alttp-seeds')->put($seed->hash.'.bps', $patch); + Storage::disk('alttp-spoilers')->put($seed->hash.'.txt', $spoiler); + + $stage = 'done'; + $seed->status = 'generated'; + $seed->save(); + } catch (\Throwable $e) { + $this->error($e->getMessage()); + $seed->status = 'error'; + $seed->error_detail = [ + 'stage' => $stage, + 'type' => get_class($e), + 'message' => $e->getMessage(), + ]; + $seed->save(); + return 1; + } + + if (file_exists($rom_file)) unlink($rom_file); + if (file_exists($settings_file)) unlink($settings_file); + if (file_exists($spoiler_file)) unlink($spoiler_file); + + return 0; + } +} diff --git a/composer.json b/composer.json index 06e6186..20611d7 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "laravel/sanctum": "^2.14.1", "laravel/tinker": "^2.7", "laravel/ui": "^3.4", - "team-reflex/discord-php": "^7.0" + "team-reflex/discord-php": "^7.0", + "z3/enemizer_linux": "6.1.0.180" }, "require-dev": { "fakerphp/faker": "^1.9.1", @@ -53,6 +54,19 @@ "@php artisan key:generate --ansi" ] }, + "repositories": [ + { + "type": "package", + "package": { + "name": "z3/enemizer_linux", + "version": "6.1.0.180", + "dist": { + "url": "https://github.com/tcprescott/Enimizer/releases/download/2mb-rom/ubuntu.16.04-x64.tar.gz", + "type": "tar" + } + } + } + ], "extra": { "laravel": { "dont-discover": [] diff --git a/composer.lock b/composer.lock index 3c72e90..1ba6b8e 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": "ac83dea6ac9ea66e7899d97abf35b4fb", + "content-hash": "6782a76fb7c2451b20cb57f93be704df", "packages": [ { "name": "beyondcode/laravel-websockets", @@ -7920,6 +7920,15 @@ "source": "https://github.com/webmozarts/assert/tree/1.10.0" }, "time": "2021-03-09T10:59:23+00:00" + }, + { + "name": "z3/enemizer_linux", + "version": "6.1.0.180", + "dist": { + "type": "tar", + "url": "https://github.com/tcprescott/Enimizer/releases/download/2mb-rom/ubuntu.16.04-x64.tar.gz" + }, + "type": "library" } ], "packages-dev": [ diff --git a/config/alttp.php b/config/alttp.php new file mode 100644 index 0000000..1be6a7a --- /dev/null +++ b/config/alttp.php @@ -0,0 +1,7 @@ + env('ALTTP_BASE_ROM', ''), + 'doors_cli' => env('ALTTP_DOORS_CLI', ''), + 'enemizer_cli' => env('ALTTP_ENEMIZER_CLI', ''), +]; diff --git a/config/filesystems.php b/config/filesystems.php index 68b2694..e743e9f 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -44,6 +44,18 @@ return [ 'throw' => false, ], + 'alttp-seeds' => [ + 'driver' => 'local', + 'root' => storage_path('app/alttp-seeds'), + 'url' => env('AOS_URL').'/alttp-seeds', + 'visibility' => 'public', + ], + + 'alttp-spoilers' => [ + 'driver' => 'local', + 'root' => storage_path('app/alttp-spoilers'), + ], + 'aos-seeds' => [ 'driver' => 'local', 'root' => storage_path('app/aos-seeds'), @@ -78,6 +90,7 @@ return [ 'links' => [ public_path('storage') => storage_path('app/public'), + public_path('alttp-seeds') => storage_path('app/alttp-seeds'), public_path('aos-seeds') => storage_path('app/aos-seeds'), ],