"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PayloadManager = void 0;
const PayloadType_1 = require("modloader64_api/PayloadType");
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const GameShark_1 = require("modloader64_api/GameShark");
class PayloadManager {
    types = new Map();
    emulator;
    logger;
    constructor(emulator, logger) {
        this.emulator = emulator;
        this.registerPayloadType(new PayloadGameshark('.payload'));
        this.registerPayloadType(new PayloadGameshark('.gsc'));
        this.logger = logger;
    }
    parseFile(file) {
        let f = path_1.default.resolve(file);
        let p = path_1.default.parse(f);
        if (this.types.has(p.ext)) {
            this.logger.info('Parsing payload: ' + path_1.default.parse(file).base + '.');
            let buf = fs_1.default.readFileSync(f);
            let r = this.types.get(p.ext).parse(f, buf, this.emulator);
            return r;
        }
        return null;
    }
    registerPayloadType(type) {
        this.types.set(type.ext, type);
    }
}
exports.PayloadManager = PayloadManager;
class PayloadGameshark extends PayloadType_1.PayloadType {
    constructor(ext) {
        super(ext);
    }
    parse(file, buf, dest) {
        let gameshark = new GameShark_1.GameShark();
        gameshark.read(buf, dest);
    }
}
//# sourceMappingURL=PayloadManager.js.map