"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MMHelper = void 0;
const Z64CORE = __importStar(require("../importsZ64"));
const JSONTemplate_1 = require("modloader64_api/JSONTemplate");
class MMHelper extends JSONTemplate_1.JSONTemplate {
    save;
    global;
    link;
    emu;
    fadeHelper = 0xFF;
    constructor(save, global, link, memory) {
        super();
        this.save = save;
        this.global = global;
        this.link = link;
        this.emu = memory;
    }
    //803FF71F: uin16: Fade in/out
    // Fade out: 0x00 -> 0xFF
    // Fade in: 0xFF -> 0x00
    isFadeIn() {
        let fadePre = this.fadeHelper;
        this.fadeHelper = this.emu.rdramRead16(0x803FF71F);
        return fadePre > this.fadeHelper;
    }
    Player_InBlockingCsMode() {
        // link + 0xA6C = stateflags1
        // link + 0xA74  = stateflags3
        // link + 0x394 = csMode
        // Global + 0x18875 = sceneLoadFlag
        // Save + 0x3F28  = magic_flag
        return ((this.link.rdramRead32(0xA6C) & 0x20000080) !== 0) || (this.link.rdramRead8(0x394) !== 0) || (this.emu.rdramReadPtr8(Z64CORE.Z64.Z64_GLOBAL_PTR, 0x18875) !== 0) ||
            ((this.link.rdramRead32(0xA6C) & 1) !== 0) || ((this.link.rdramRead8(0xA74) & 0x80) !== 0) ||
            (this.emu.rdramRead16(Z64CORE.Z64.Z64_SAVE + 0x3F28) !== 0);
    }
    isLinkEnteringLoadingZone() {
        let r = this.link.rawStateValue;
        return (r & 0x000000ff) === 1;
    }
    isTitleScreen() {
        return this.save.checksum === 0 || !this.isSceneNumberValid();
    }
    isSceneNumberValid() {
        return this.global.scene <= 112;
    }
    isPaused() {
        let paused = 0x801D1500;
        return this.emu.rdramRead32(paused) !== 0x3;
    }
    isInterfaceShown() {
        let interface_shown = 0x803FD77B;
        return this.emu.rdramRead8(interface_shown) === 0xFF;
    }
}
exports.MMHelper = MMHelper;
//# sourceMappingURL=MMHelper.js.map