"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MupenMonkeyPatches = exports.MonkeyPatch_rdramWritePtrF32 = exports.MonkeyPatch_rdramWriteF32 = exports.MonkeyPatch_rdramReadPtrF32 = exports.MonkeyPatch_rdramReadF32 = void 0;
const IMonkeyPatch_1 = require("./IMonkeyPatch");
class MonkeyPatch_rdramReadF32 extends IMonkeyPatch_1.MonkeyPatch {
    mupen;
    constructor(mupen) {
        super();
        this.mupen = mupen;
    }
    patch() {
        this.replacement = (addr) => {
            let data = this.mupen.M64p.Memory.rdramReadBuffer(addr, 4);
            return data.readFloatBE(0);
        };
        this.original = this.mupen.M64p.Memory.rdramReadF32;
        this.mupen.M64p.Memory['rdramReadF32'] = this.replacement;
    }
    unpatch() {
        this.mupen.M64p.Memory['rdramReadF32'] = this.original;
    }
}
exports.MonkeyPatch_rdramReadF32 = MonkeyPatch_rdramReadF32;
class MonkeyPatch_rdramReadPtrF32 extends IMonkeyPatch_1.MonkeyPatch {
    mupen;
    constructor(mupen) {
        super();
        this.mupen = mupen;
    }
    patch() {
        this.replacement = (addr, offset) => {
            let ptr = this.mupen.M64p.Memory.rdramRead32(addr);
            let data = this.mupen.M64p.Memory.rdramReadBuffer(ptr + offset, 4);
            return data.readFloatBE(0);
        };
        this.original = this.mupen.M64p.Memory.rdramReadPtrF32;
        this.mupen.M64p.Memory['rdramReadPtrF32'] = this.replacement;
    }
    unpatch() {
        this.mupen.M64p.Memory['rdramReadPtrF32'] = this.original;
    }
}
exports.MonkeyPatch_rdramReadPtrF32 = MonkeyPatch_rdramReadPtrF32;
class MonkeyPatch_rdramWriteF32 extends IMonkeyPatch_1.MonkeyPatch {
    mupen;
    buf = Buffer.alloc(4);
    constructor(mupen) {
        super();
        this.mupen = mupen;
    }
    patch() {
        this.replacement = (addr, float) => {
            this.buf.writeFloatBE(float);
            this.mupen.M64p.Memory.rdramWriteBuffer(addr, this.buf);
        };
        this.original = this.mupen.M64p.Memory.rdramWriteF32;
        this.mupen.M64p.Memory['rdramWriteF32'] = this.replacement;
    }
    unpatch() {
        this.mupen.M64p.Memory['rdramWriteF32'] = this.original;
    }
}
exports.MonkeyPatch_rdramWriteF32 = MonkeyPatch_rdramWriteF32;
class MonkeyPatch_rdramWritePtrF32 extends IMonkeyPatch_1.MonkeyPatch {
    mupen;
    buf = Buffer.alloc(4);
    constructor(mupen) {
        super();
        this.mupen = mupen;
    }
    patch() {
        this.replacement = (addr, offset, float) => {
            this.buf.writeFloatBE(float);
            let ptr = this.mupen.M64p.Memory.rdramRead32(addr);
            this.mupen.M64p.Memory.rdramWriteBuffer(ptr + offset, this.buf);
        };
        this.original = this.mupen.M64p.Memory.rdramWritePtrF32;
        this.mupen.M64p.Memory['rdramWritePtrF32'] = this.replacement;
    }
    unpatch() {
        this.mupen.M64p.Memory['rdramWritePtrF32'] = this.original;
    }
}
exports.MonkeyPatch_rdramWritePtrF32 = MonkeyPatch_rdramWritePtrF32;
class MupenMonkeyPatches {
    static patch(mupen) {
        new MonkeyPatch_rdramReadF32(mupen).patch();
        new MonkeyPatch_rdramReadPtrF32(mupen).patch();
        new MonkeyPatch_rdramWriteF32(mupen).patch();
        new MonkeyPatch_rdramWritePtrF32(mupen).patch();
    }
}
exports.MupenMonkeyPatches = MupenMonkeyPatches;
//# sourceMappingURL=Mupen.js.map