From 2ad31ae9ffc4289ac0abfa407ef20e535f0f5076 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Sat, 3 Sep 2022 17:03:17 -0400 Subject: [PATCH] decomp: provide a list of valid object names when decomping --- src/decomp/decomp-tools.ts | 48 +++++++++++++++++++++++++++++++++++--- src/decomp/type-caster.ts | 13 +---------- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/decomp/decomp-tools.ts b/src/decomp/decomp-tools.ts index fd002f6..e6a3b62 100644 --- a/src/decomp/decomp-tools.ts +++ b/src/decomp/decomp-tools.ts @@ -1,5 +1,5 @@ import { exec, execFile } from "child_process"; -import { existsSync, promises as fs } from "fs"; +import { existsSync, promises as fs, readFileSync } from "fs"; import * as vscode from "vscode"; import { determineGameFromPath, GameName, openFile } from "../utils/file-utils"; import { open_in_pdf } from "./man-page"; @@ -237,6 +237,39 @@ async function decompFiles(decompConfig: string, fileNames: string[]) { updateStatus(DecompStatus.Idle); } +async function getValidObjectNames(gameName: string) { + if (projectRoot === undefined) { + projectRoot = getWorkspaceFolderByName("jak-project"); + if (projectRoot === undefined) { + return undefined; + } + } + + // Look for the `all_objs.json` file + const objsPath = path.join( + projectRoot.fsPath, + "goal_src", + gameName, + "build", + "all_objs.json" + ); + if (!existsSync(objsPath)) { + return undefined; + } + const objsData = await fs.readFile(objsPath, { + encoding: "utf-8", + }); + const objs = JSON.parse(objsData); + const names = []; + for (const obj of objs) { + if (obj[2] != 3) { + continue; + } + names.push(obj[0]); + } + return names; +} + async function decompSpecificFile() { // Prompt the user for the game name let gameName; @@ -258,8 +291,17 @@ async function decompSpecificFile() { gameName = GameName.Jak2; } } - // Prompt the user for the file name - const fileName = await vscode.window.showInputBox({ title: "Object Name?" }); + const validNames = await getValidObjectNames(gameNameSelection); + let fileName; + if (validNames === undefined || validNames.length <= 0) { + // Prompt the user for the file name + fileName = await vscode.window.showInputBox({ title: "Object Name?" }); + } else { + fileName = await vscode.window.showQuickPick(validNames, { + title: "File to Decompile?", + }); + } + if (fileName === undefined) { await vscode.window.showErrorMessage( "OpenGOAL - can't decompile, didn't provide an object name" diff --git a/src/decomp/type-caster.ts b/src/decomp/type-caster.ts index dd5b980..261f9c4 100644 --- a/src/decomp/type-caster.ts +++ b/src/decomp/type-caster.ts @@ -3,19 +3,8 @@ import { getExtensionContext } from "../context"; import * as vscode from "vscode"; import { basename, join } from "path"; -import { getWorkspaceFolderByName } from "../utils/workspace"; -import { existsSync, readFileSync, writeFileSync } from "fs"; +import { readFileSync, writeFileSync } from "fs"; import { parse, stringify } from "comment-json"; -import { - getConfig, - updateJak1DecompConfigDirectory, - updateJak2DecompConfigDirectory, -} from "../config/config"; -import { - determineGameFromPath, - GameName, - getDirectoriesInDir, -} from "../utils/file-utils"; import { getDecompilerConfigDirectory } from "../utils/decomp-tools"; enum CastKind {