"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.SaveContext = void 0;
const JSONTemplate_1 = require("modloader64_api/JSONTemplate");
const Z64API = __importStar(require("../../API/imports"));
const Z64CORE = __importStar(require("../importsZ64"));
class SaveContext extends JSONTemplate_1.JSONTemplate {
    emulator;
    save_context = Z64CORE.Z64.Z64_SAVE;
    inventory;
    questStatus;
    owlStatues;
    keyManager;
    dungeonItemManager;
    photo;
    stray;
    skull;
    swords;
    sword_helper;
    shields;
    commandBuffer;
    magic_meter_size_addr = this.save_context + 0x38;
    magic_fill_cap_addr = this.save_context + 0x39;
    magic_flag_1_addr = this.save_context + 0x40;
    magic_flag_2_addr = this.save_context + 0x41;
    jsonFields = [
        'entrance_index',
        'cutscene_number',
        'world_time',
        'world_night_flag',
        'minimap_flags',
        'map_visible',
        'map_visited',
        'player_name',
        'heart_containers',
        'magic',
        'magic_meter_size',
        'magic_current',
        'rupee_count',
        'owlStatues',
        'checksum',
        'form',
        'swords',
        'shields',
        'double_defense',
        'have_tatl',
        'inventory',
        'masks',
        'questStatus',
        'intro_flag',
        'updrades',
        'spider_house_mask_order',
        'bomber_code',
        'permFlags',
        'photo',
        'skull',
        'stray',
        'pictoboxUsed',
        'bank',
        'lottery_numbers_day1',
        'lottery_numbers_day2',
        'lottery_numbers_day3',
        'permSceneData',
        'weekEventFlags',
        'infTable'
    ];
    constructor(emu, log, core) {
        super();
        this.emulator = emu;
        this.swords = new Z64CORE.Z64.SwordsEquipment(emu, core);
        this.sword_helper = this.swords;
        this.shields = new Z64CORE.Z64.ShieldsEquipment(emu);
        this.inventory = new Z64CORE.MM.Inventory(emu, log);
        this.questStatus = new Z64CORE.MM.QuestStatus(emu);
        this.owlStatues = new Z64CORE.MM.OwlStatues(emu);
        this.keyManager = new Z64CORE.MM.KeyManager(emu);
        this.dungeonItemManager = new Z64CORE.Z64.DungeonItemManager(emu);
        this.photo = new Z64CORE.MM.Photo(emu, this);
        this.stray = new Z64CORE.MM.Stray(emu);
        this.skull = new Z64CORE.MM.Skull(emu);
    }
    get checksum() {
        return this.emulator.rdramReadBuffer(0x801EF694, 0x6).readUIntBE(0x0, 0x6);
    }
    get form() {
        return this.emulator.rdramRead8(this.save_context + 0x0020);
    }
    get hearts() {
        return this.emulator.rdramRead16(0x801EF6A6);
    }
    set hearts(flag) {
        this.emulator.rdramWrite16(0x801EF6A6, flag);
    }
    get health_mod() {
        return this.emulator.rdramRead8(0x801F35CA);
    }
    set health_mod(flag) {
        this.emulator.rdramWrite16(0x801F35CA, flag);
    }
    get deku_b_state() {
        return this.emulator.rdramRead32(0x801EF6C8);
    }
    set deku_b_state(flag) {
        this.emulator.rdramWrite32(0x801EF6C8, flag);
    }
    get razor_hits() {
        return this.emulator.rdramRead16(0x801EF6AC);
    }
    set razor_hits(flag) {
        this.emulator.rdramWrite16(0x801EF6AC, flag);
    }
    get magic() {
        return this.emulator.rdramRead8(this.magic_fill_cap_addr);
    }
    set magic(flag) {
        this.emulator.rdramWrite8(this.magic_fill_cap_addr, flag);
    }
    get magic_meter_size() {
        return this.emulator.rdramRead8(this.magic_meter_size_addr);
    }
    // Several things need to be set in order for magic to function properly.
    set magic_meter_size(size) {
        switch (size) {
            case 0 /* Z64API.Z64.Magic.NONE */: {
                this.emulator.rdramWrite8(this.magic_flag_1_addr, 0);
                this.emulator.rdramWrite8(this.magic_flag_2_addr, 0);
                this.emulator.rdramWrite8(this.magic_fill_cap_addr, 0 /* Z64API.Z64.MagicQuantities.NONE */);
                this.emulator.rdramWrite8(this.magic_meter_size_addr, 0);
                break;
            }
            case 1 /* Z64API.Z64.Magic.NORMAL */: {
                this.emulator.rdramWrite8(this.magic_flag_1_addr, 1);
                this.emulator.rdramWrite8(this.magic_flag_2_addr, 0);
                this.emulator.rdramWrite8(this.magic_fill_cap_addr, 48 /* Z64API.Z64.MagicQuantities.NORMAL */);
                this.emulator.rdramWrite8(this.magic_meter_size_addr, 0);
                break;
            }
            case 2 /* Z64API.Z64.Magic.EXTENDED */: {
                this.emulator.rdramWrite8(this.magic_flag_1_addr, 1);
                this.emulator.rdramWrite8(this.magic_flag_2_addr, 1);
                this.emulator.rdramWrite8(this.magic_fill_cap_addr, 96 /* Z64API.Z64.MagicQuantities.EXTENDED */);
                this.emulator.rdramWrite8(this.magic_meter_size_addr, 0);
                break;
            }
        }
    }
    get magic_current() {
        return this.emulator.rdramRead8(0x801F35A0);
    }
    set magic_current(amount) {
        this.emulator.rdramWrite8(0x801F35A0, amount);
    }
    get owl_statues() {
        return this.emulator.rdramRead16(0x801EF6B6);
    }
    set owl_statues(flag) {
        this.emulator.rdramWrite16(0x801EF6B6, flag);
    }
    get map_visible() {
        return this.emulator.rdramReadBuffer(0x801F05D0, 0x4);
    }
    set map_visible(flag) {
        this.emulator.rdramWriteBuffer(0x801F05D0, flag);
    }
    get map_visited() {
        return this.emulator.rdramReadBuffer(0x801F05CC, 0x4);
    }
    set map_visited(flag) {
        this.emulator.rdramWriteBuffer(0x801F05CC, flag);
    }
    get tunic_boots() {
        return this.emulator.rdramRead8(0x801EF6DC);
    }
    set tunic_boots(flag) {
        this.emulator.rdramWrite8(0x801EF6DC, flag);
    }
    get sword_sheild() {
        return this.emulator.rdramRead8(0x801EF6DD);
    }
    set sword_sheild(flag) {
        this.emulator.rdramWrite8(0x801EF6DD, flag);
    }
    get item_inventory() {
        return this.emulator.rdramReadBuffer(0x801EF6E0, 0x30);
    }
    set item_inventory(flag) {
        this.emulator.rdramWriteBuffer(0x801EF6E0, flag);
    }
    get masks() {
        return this.emulator.rdramReadBuffer(0x801EF6F8, 0x18);
    }
    set masks(flag) {
        this.emulator.rdramWriteBuffer(0x801EF6F8, flag);
    }
    get item_amts() {
        return this.emulator.rdramReadBuffer(0x801EF710, 0x18);
    }
    set item_amts(flag) {
        this.emulator.rdramWriteBuffer(0x801EF710, flag);
    }
    get upgrades() {
        return this.emulator.rdramRead32(0x801EF728);
    }
    set upgrades(flag) {
        this.emulator.rdramWrite32(0x801EF728, flag);
    }
    get questflg1() {
        return this.emulator.rdramRead8(0x801EF72C);
    }
    set questflg1(flag) {
        this.emulator.rdramWrite8(0x801EF72C, flag);
    }
    get questflg2() {
        return this.emulator.rdramRead8(0x801EF72D);
    }
    set questflg2(flag) {
        this.emulator.rdramWrite8(0x801EF72D, flag);
    }
    get questflg3() {
        return this.emulator.rdramRead8(0x801EF72E);
    }
    set questflg3(flag) {
        this.emulator.rdramWrite8(0x801EF72E, flag);
    }
    get questflg4() {
        return this.emulator.rdramRead8(0x801EF72F);
    }
    set questflg4_flag(flag) {
        this.emulator.rdramWrite8(0x801EF72F, flag);
    }
    get double_defense() {
        return this.emulator.rdramRead8(0x801EF743);
    }
    set double_defense(flag) {
        this.emulator.rdramWrite8(0x801EF743, flag);
    }
    get permSceneData() {
        return this.emulator.rdramReadBuffer(0x801EF768, 0xD20);
    }
    set permSceneData(flag) {
        this.emulator.rdramWriteBuffer(0x801EF768, flag);
    }
    get weekEventFlags() {
        return this.emulator.rdramReadBuffer(0x801F0568, 0x64);
    }
    set weekEventFlags(buf) {
        this.emulator.rdramWriteBuffer(0x801F0568, buf);
    }
    get infTable() {
        return this.emulator.rdramReadBuffer(0x801F067C, 0x8);
    }
    set infTable(flag) {
        this.emulator.rdramWriteBuffer(0x801F067C, flag);
    }
    get minimap_flags() {
        return this.emulator.rdramReadBuffer(0x801F0514, 0x1C);
    }
    set minimap_flags(flag) {
        this.emulator.rdramWriteBuffer(0x801F0514, flag);
    }
    /*get item_Flags(): Buffer {
        return this.emulator.rdramReadBuffer(inventory, 0x18);
    }
    set item_Flags(flag: Buffer) {
        this.emulator.rdramWriteBuffer(inventory, flag);
    }*/
    get day_time() {
        return this.emulator.rdramRead16(0x801EF67C);
    }
    set day_time(flag) {
        this.emulator.rdramWrite16(0x801EF67C, flag);
    }
    get day_night() {
        return this.emulator.rdramRead32(0x801EF680);
    }
    set day_night(flag) {
        this.emulator.rdramWrite32(0x801EF680, flag);
    }
    get time_speed() {
        return this.emulator.rdramReadS32(0x801EF684);
    }
    set time_speed(flag) {
        this.emulator.rdramWrite32(0x801EF684, flag);
    }
    get current_day() {
        return this.emulator.rdramRead32(0x801EF688);
    }
    set current_day(flag) {
        this.emulator.rdramWrite32(0x801EF688, flag);
    }
    get current_transformation() {
        return this.emulator.rdramRead8(0x801EF690);
    }
    set current_transformation(flag) {
        this.emulator.rdramWrite8(0x801EF690, flag);
    }
    get intro_flag() {
        return this.emulator.rdramRead8(0x801EF675);
    }
    set intro_flag(flag) {
        this.emulator.rdramWrite8(0x801EF675, flag);
    }
    get have_tatl() {
        return this.emulator.rdramRead8(0x801EF692);
    }
    set have_tatl(flag) {
        this.emulator.rdramWrite8(0x801EF692, flag);
    }
    get heart_containers() {
        return this.emulator.rdramRead16(0x801EF6A4) / 0x10;
    }
    set heart_containers(flag) {
        this.emulator.rdramWrite16(0x801EF6A4, flag * 0x10);
    }
    get rupees() {
        return this.emulator.rdramRead16(0x801EF6AA);
    }
    set rupees(flag) {
        this.emulator.rdramWrite16(0x801EF6AA, flag);
    }
    get bank() {
        return this.emulator.rdramRead16(0x801F054E);
    }
    set bank(flag) {
        this.emulator.rdramWrite16(0x801F054E, flag);
    }
    get lottery_numbers_day1() {
        return this.emulator.rdramReadBuffer(0x801F065C, 0x3);
    }
    set lottery_numbers_day1(flag) {
        this.emulator.rdramWriteBuffer(0x801F065C, flag);
    }
    get lottery_numbers_day2() {
        return this.emulator.rdramReadBuffer(0x801F065F, 0x3);
    }
    set lottery_numbers_day2(flag) {
        this.emulator.rdramWriteBuffer(0x801F065F, flag);
    }
    get lottery_numbers_day3() {
        return this.emulator.rdramReadBuffer(0x801F0662, 0x3);
    }
    set lottery_numbers_day3(flag) {
        this.emulator.rdramWriteBuffer(0x801F0662, flag);
    }
    get spider_house_mask_order() {
        return this.emulator.rdramReadBuffer(0x801F0665, 0x6);
    }
    set spider_house_mask_order(flag) {
        this.emulator.rdramWriteBuffer(0x801F0665, flag);
    }
    get bomber_code() {
        return this.emulator.rdramReadBuffer(0x801F066B, 0x5);
    }
    set bomber_code(flag) {
        this.emulator.rdramWriteBuffer(0x801F066B, flag);
    }
    get pictoboxUsed() {
        return this.emulator.rdramReadBit8(0x801EF72C, 6);
    }
    set pictoboxUsed(b) {
        this.emulator.rdramWriteBit8(0x801EF72C, 6, b);
    }
    get permFlags() {
        return this.emulator.rdramReadBuffer(0x801F35D8, 0x960);
    }
    set permFlags(b) {
        this.emulator.rdramWriteBuffer(0x801F35D8, b);
    }
}
exports.SaveContext = SaveContext;
//# sourceMappingURL=SaveContext.js.map