]> git.localhorst.tv Git - alttp.git/commitdiff
add ALttP seed generator
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 18 May 2022 11:53:08 +0000 (13:53 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 18 May 2022 12:42:12 +0000 (14:42 +0200)
.env.example
app/Console/Commands/GenerateAlttpSeed.php [new file with mode: 0644]
composer.json
composer.lock
config/alttp.php [new file with mode: 0644]
config/filesystems.php

index 381184516838d1c2dcf101095a6cb95d7c58fc91..8105545c327f60ec75dfe0eebab43523bc795a28 100644 (file)
@@ -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 (file)
index 0000000..466f2f2
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Beat\Encoder;
+use App\Models\AlttpSeed;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Http;
+use Illuminate\Support\Facades\Storage;
+use Symfony\Component\Process\Process;
+
+class GenerateAlttpSeed extends Command
+{
+       /**
+        * The name and signature of the console command.
+        *
+        * @var string
+        */
+       protected $signature = 'alttp:generate {id}';
+
+       /**
+        * The console command description.
+        *
+        * @var string
+        */
+       protected $description = 'Generate ALttP seed';
+
+       /**
+        * Execute the console command.
+        *
+        * @return int
+        */
+       public function handle()
+       {
+               $seed = AlttpSeed::findOrFail($this->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;
+       }
+}
index 06e61869e993665e1a1d93be74ff56f350b003cb..20611d7d3cb266c18cdbb3261e17825741d755eb 100644 (file)
@@ -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",
             "@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": []
index 3c72e9031f6c050f7d0128f5a348045a9dee7aa8..1ba6b8e53421bf1445d6b7f7ce936d64e7402a7e 100644 (file)
@@ -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",
                 "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 (file)
index 0000000..1be6a7a
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+
+return [
+       'base_rom' => env('ALTTP_BASE_ROM', ''),
+       'doors_cli' => env('ALTTP_DOORS_CLI', ''),
+       'enemizer_cli' => env('ALTTP_ENEMIZER_CLI', ''),
+];
index 68b2694e004cdc85c3124420c351a734d07c94a1..e743e9ff6c5bac072032a45ef584eb30a9afa33e 100644 (file)
@@ -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'),
        ],