//
// Generated by dtk
// Translation Unit: m_Do_ext.cpp
//

#include "m_Do/m_Do_ext.h"
#include "JSystem/J3DGraphBase/J3DTransform.h"
#include "JSystem/JKernel/JKRArchive.h"
#include "JSystem/JKernel/JKRSolidHeap.h"
#include "JSystem/JMath/JMath.h"
#include "JSystem/JUtility/JUTAssert.h"
#include "JSystem/JUtility/JUTCacheFont.h"
#include "JSystem/JKernel/JKRHeap.h"
#include "SSystem/SComponent/c_m3d.h"
#include "d/d_com_inf_game.h"
#include "d/d_s_play.h"
#include "m_Do/m_Do_mtx.h"
#include "m_Do/m_Do_printf.h"

/* 8000DA70-8000DCF0       .text mDoExt_setJ3DData__FPA4_fPC16J3DTransformInfoUs */
void mDoExt_setJ3DData(Mtx mtx, const J3DTransformInfo* transformInfo, u16 param_2) {
    bool local_28;
    if (cM3d_IsZero(transformInfo->mScale.x - 1.0f) && cM3d_IsZero(transformInfo->mScale.y - 1.0f) && cM3d_IsZero(transformInfo->mScale.z - 1.0f)) {
        j3dSys.getModel()->setScaleFlag(param_2, 1);
        local_28 = true;
    } else {
        j3dSys.getModel()->setScaleFlag(param_2, 0);
        local_28 = false;
    }
    mtx[0][3] = transformInfo->mTranslate.x;
    mtx[1][3] = transformInfo->mTranslate.y;
    mtx[2][3] = transformInfo->mTranslate.z;

    if (!local_28) {
        mtx[0][0] *= transformInfo->mScale.x;
        mtx[0][1] *= transformInfo->mScale.y;
        mtx[0][2] *= transformInfo->mScale.z;
        mtx[1][0] *= transformInfo->mScale.x;
        mtx[1][1] *= transformInfo->mScale.y;
        mtx[1][2] *= transformInfo->mScale.z;
        mtx[2][0] *= transformInfo->mScale.x;
        mtx[2][1] *= transformInfo->mScale.y;
        mtx[2][2] *= transformInfo->mScale.z;
    }
    if (j3dSys.getModel()->getModelData()->getJointNodePointer(param_2)->getScaleCompensate() == 1) {
        f32 x = 1.0f / J3DSys::mParentS.x;
        f32 y = 1.0f / J3DSys::mParentS.y;
        f32 z = 1.0f / J3DSys::mParentS.z;
        mtx[0][0] *= x;
        mtx[0][1] *= x;
        mtx[0][2] *= x;
        mtx[1][0] *= y;
        mtx[1][1] *= y;
        mtx[1][2] *= y;
        mtx[2][0] *= z;
        mtx[2][1] *= z;
        mtx[2][2] *= z;
    }
    mDoMtx_concat(J3DSys::mCurrentMtx, mtx, J3DSys::mCurrentMtx);
    j3dSys.getModel()->setAnmMtx(param_2, J3DSys::mCurrentMtx);
    J3DSys::mParentS.x = transformInfo->mScale.x;
    J3DSys::mParentS.y = transformInfo->mScale.y;
    J3DSys::mParentS.z = transformInfo->mScale.z;
}

/* 8000DCF0-8000DCF4       .text getTransform__15J3DAnmTransformCFUsP16J3DTransformInfo */
void J3DAnmTransform::getTransform(u16, J3DTransformInfo*) const {}

/* 8000DCF4-8000DD4C       .text isCurrentSolidHeap__Fv */
bool isCurrentSolidHeap() {
    if (JKRGetCurrentHeap()->getHeapType() != 'SLID') {
        OSReport_Error("ソリッドヒープちゃうがな！\n");
        return false;
    }
    return true;
}

/* 8000DD4C-8000DF24       .text initPlay__14mDoExt_baseAnmFsifssb */
int mDoExt_baseAnm::initPlay(s16 i_frameMax, int i_attribute, f32 i_rate, s16 i_startF, s16 i_endF, bool i_modify) {
    JUT_ASSERT(421, i_modify || isCurrentSolidHeap());
    if (!i_modify) {
        mFrameCtrl = new J3DFrameCtrl();
        if (!mFrameCtrl) {
            return 0;
        }
    }

    mFrameCtrl->setStart(i_startF);

    if (i_endF < 0) {
        mFrameCtrl->init(i_frameMax);
    } else {
        mFrameCtrl->init(i_endF);
    }
    mFrameCtrl->setAttribute(i_attribute);
    mFrameCtrl->setRate(i_rate);

    if (i_rate >= 0.0f) {
        mFrameCtrl->setFrame(i_startF);
    } else {
        mFrameCtrl->setFrame(mFrameCtrl->getEnd());
    }

    mFrameCtrl->setLoop(mFrameCtrl->getFrame());

    return 1;
}

/* 8000DF24-8000DFC4       .text play__14mDoExt_baseAnmFv */
int mDoExt_baseAnm::play() {
    JUT_ASSERT(462, mFrameCtrl != 0);
    mFrameCtrl->update();
    return isStop();
}

/* 8000DFC4-8000DFF0       .text init__13mDoExt_bpkAnmFP12J3DModelDataP11J3DAnmColoriifssbi */
int mDoExt_bpkAnm::init(J3DModelData* i_modelData, J3DAnmColor* i_bpk, int i_anmPlay, int i_attribute, f32 i_rate, s16 i_startF, s16 i_endF, bool i_modify, int i_entry) {
    return init(&i_modelData->getMaterialTable(), i_bpk, i_anmPlay, i_attribute, i_rate, i_startF, i_endF, i_modify, i_entry);
}

/* 8000DFF0-8000E014       .text entry__13mDoExt_bpkAnmFP12J3DModelDataf */
void mDoExt_bpkAnm::entry(J3DModelData* i_modelData, f32 param_1) {
    entry(&i_modelData->getMaterialTable(), param_1);
}

/* 8000E014-8000E2A8       .text init__13mDoExt_bpkAnmFP16J3DMaterialTableP11J3DAnmColoriifssbi */
int mDoExt_bpkAnm::init(J3DMaterialTable* i_matTable, J3DAnmColor* i_bpk, int i_anmPlay, int i_attribute, f32 i_rate, s16 i_startF, s16 i_endF, bool i_modify, int i_entry) {

    JUT_ASSERT(531, i_modify || isCurrentSolidHeap());
    JUT_ASSERT(533, i_matTable != 0 && i_bpk != 0);
    mpAnm = i_bpk;
    mpAnm->searchUpdateMaterialID(i_matTable);

    u16 updateMaterialNum = mpAnm->getUpdateMaterialNum();
    if (!i_modify) {
        mUpdateMaterialNum = updateMaterialNum;
        JUT_ASSERT(541, mUpdateMaterialNum);
        field_0xc = new J3DMatColorAnm[mUpdateMaterialNum];
        if (!field_0xc) {
            return 0;
        }
    }
    JUT_ASSERT(548, updateMaterialNum <= mUpdateMaterialNum);
    J3DMatColorAnm* matColorAnm = field_0xc;
    for (u16 i = 0; i < updateMaterialNum; i++) {
        matColorAnm->setAnmColor(mpAnm);
        matColorAnm->setAnmIndex(i);
        matColorAnm++;
    }

    if (!i_modify && i_entry) {
        i_matTable->setMatColorAnimator(mpAnm, field_0xc);
    }

    if (i_anmPlay) {
        if (initPlay(mpAnm->getFrameMax(), i_attribute, i_rate, i_startF, i_endF, i_modify) == 0) {
            return 0;
        }
    }
    return 1;
}

/* 8000E2F4-8000E32C       .text entry__13mDoExt_bpkAnmFP16J3DMaterialTablef */
void mDoExt_bpkAnm::entry(J3DMaterialTable* i_matTable, f32 i_frame) {
    mpAnm->setFrame(i_frame);
    i_matTable->setMatColorAnimator(mpAnm, field_0xc);
}

/* 8000E32C-8000E358       .text init__13mDoExt_btpAnmFP12J3DModelDataP16J3DAnmTexPatterniifssbi */
int mDoExt_btpAnm::init(J3DModelData* i_modelData, J3DAnmTexPattern* i_btp, int i_anmPlay, int i_attribute, f32 i_rate, s16 i_startF, s16 i_endF, bool i_modify, int i_entry) {
    init(&i_modelData->getMaterialTable(), i_btp, i_anmPlay, i_attribute, i_rate, i_startF, i_endF, i_modify, i_entry);
}

/* 8000E358-8000E37C       .text entry__13mDoExt_btpAnmFP12J3DModelDatas */
void mDoExt_btpAnm::entry(J3DModelData* i_modelData, s16 i_frame) {
    entry(&i_modelData->getMaterialTable(), i_frame);
}

/* 8000E37C-8000E610       .text init__13mDoExt_btpAnmFP16J3DMaterialTableP16J3DAnmTexPatterniifssbi */
int mDoExt_btpAnm::init(J3DMaterialTable* i_matTable, J3DAnmTexPattern* i_btp, int i_anmPlay, int i_attribute, f32 i_rate, s16 i_startF, s16 i_endF, bool i_modify, int i_entry) {
    JUT_ASSERT(648, i_modify || isCurrentSolidHeap());
    JUT_ASSERT(650, i_matTable != 0 && i_btp != 0);
    mpAnm = i_btp;
    mpAnm->searchUpdateMaterialID(i_matTable);

    u16 updateMaterialNum = mpAnm->getUpdateMaterialNum();
    if (!i_modify) {
        mUpdateMaterialNum = updateMaterialNum;
        JUT_ASSERT(658, mUpdateMaterialNum);
        field_0xc = new J3DTexNoAnm[mUpdateMaterialNum];
        if (!field_0xc) {
            return 0;
        }
    }
    JUT_ASSERT(665, updateMaterialNum <= mUpdateMaterialNum);
    J3DTexNoAnm* texNoAnm = field_0xc;
    for (u16 i = 0; i < updateMaterialNum; i++) {
        texNoAnm->setAnmTexPattern(mpAnm);
        texNoAnm->setAnmIndex(i);
        texNoAnm++;
    }

    if (!i_modify && i_entry) {
        i_matTable->setTexNoAnimator(mpAnm, field_0xc);
    }

    if (i_anmPlay) {
        if (initPlay(mpAnm->getFrameMax(), i_attribute, i_rate, i_startF, i_endF, i_modify) == 0) {
            return 0;
        }
    }
    return 1;
}

/* 8000E674-8000E6CC       .text entry__13mDoExt_btpAnmFP16J3DMaterialTables */
void mDoExt_btpAnm::entry(J3DMaterialTable* i_matTable, s16 i_frame) {
    mpAnm->setFrame(i_frame);
    i_matTable->setTexNoAnimator(mpAnm, field_0xc);
}

/* 8000E6CC-8000E6F8       .text init__13mDoExt_btkAnmFP12J3DModelDataP19J3DAnmTextureSRTKeyiifssbi */
int mDoExt_btkAnm::init(J3DModelData* i_modelData, J3DAnmTextureSRTKey* i_btk, int i_anmPlay, int i_attribute, f32 i_rate, s16 i_startF, s16 i_endF, bool i_modify, int i_entry) {
    init(&i_modelData->getMaterialTable(), i_btk, i_anmPlay, i_attribute, i_rate, i_startF, i_endF, i_modify, i_entry);
}

/* 8000E6F8-8000E71C       .text entry__13mDoExt_btkAnmFP12J3DModelDataf */
void mDoExt_btkAnm::entry(J3DModelData* i_modelData, f32 i_frame) {
    entry(&i_modelData->getMaterialTable(), i_frame);
}

/* 8000E71C-8000EAE4       .text init__13mDoExt_btkAnmFP16J3DMaterialTableP19J3DAnmTextureSRTKeyiifssbi */
int mDoExt_btkAnm::init(J3DMaterialTable* i_matTable, J3DAnmTextureSRTKey* i_btk, int i_anmPlay, int i_attribute, f32 i_rate, s16 i_startF, s16 i_endF, bool i_modify, int i_entry) {
    JUT_ASSERT(781, i_modify || isCurrentSolidHeap());
    JUT_ASSERT(783, i_matTable != 0 && i_btk != 0);
    mpAnm = i_btk;
    mpAnm->searchUpdateMaterialID(i_matTable);

    u16 updateMaterialNum = mpAnm->getUpdateMaterialNum();
    if (!i_modify) {
        mUpdateMaterialNum = updateMaterialNum;
        JUT_ASSERT(791, mUpdateMaterialNum);
        for (u16 i = 0; i < mUpdateMaterialNum; i++) {
            u16 materialId = mpAnm->getUpdateMaterialID(i);
            if (materialId != 0xFFFF) {
                J3DMaterial* material = i_matTable->getMaterialNodePointer(materialId);
                u8 texMtxId = mpAnm->getUpdateTexMtxID(i);
                if (texMtxId != 0xFF) {
                    J3DTexMtx* texMtx = material->getTexGenBlock()->getTexMtx(texMtxId);
                    if (!texMtx) {
                        texMtx = new J3DTexMtx();
                    }
                }
            }
        }
        mpTexMtxAnm = new J3DTexMtxAnm[mUpdateMaterialNum];
        if (!mpTexMtxAnm) {
            return 0;
        }
    }
    JUT_ASSERT(811, updateMaterialNum <= mUpdateMaterialNum);
    J3DTexMtxAnm* texMtxAnm = mpTexMtxAnm;
    for (u16 i = 0; i < updateMaterialNum; i++) {
        texMtxAnm->setAnmTransform(mpAnm);
        texMtxAnm->setAnmIndex(i);
        texMtxAnm++;
    }

    if (!i_modify && i_entry) {
        i_matTable->setTexMtxAnimator(mpAnm, mpTexMtxAnm, NULL);
    }

    if (i_anmPlay) {
        if (initPlay(mpAnm->getFrameMax(), i_attribute, i_rate, i_startF, i_endF, i_modify) == 0) {
            return 0;
        }
    }
    return 1;
}

/* 8000EB38-8000EB74       .text entry__13mDoExt_btkAnmFP16J3DMaterialTablef */
void mDoExt_btkAnm::entry(J3DMaterialTable* i_matTable, f32 i_frame) {
    mpAnm->setFrame(i_frame);
    i_matTable->setTexMtxAnimator(mpAnm, mpTexMtxAnm, NULL);
}

/* 8000EB74-8000EBA0       .text init__13mDoExt_brkAnmFP12J3DModelDataP15J3DAnmTevRegKeyiifssbi */
int mDoExt_brkAnm::init(J3DModelData* i_modelData, J3DAnmTevRegKey* i_brk, int i_anmPlay,
                        int i_attribute, f32 i_rate, s16 i_start, s16 i_end, bool i_modify, int i_entry) {
    return init(&i_modelData->getMaterialTable(), i_brk, i_anmPlay, i_attribute, i_rate,
                i_start, i_end, i_modify, i_entry);
}

/* 8000EBA0-8000EBC4       .text entry__13mDoExt_brkAnmFP12J3DModelDataf */
void mDoExt_brkAnm::entry(J3DModelData* i_modelData, f32 i_frame) {
    entry(&i_modelData->getMaterialTable(), i_frame);
}

/* 8000EBC4-8000EEE8       .text init__13mDoExt_brkAnmFP16J3DMaterialTableP15J3DAnmTevRegKeyiifssbi */
int mDoExt_brkAnm::init(J3DMaterialTable* i_matTable, J3DAnmTevRegKey* i_brk, int i_anmPlay, int i_attribute, f32 i_rate, s16 i_startF, s16 i_endF, bool i_modify, int i_entry) {
    JUT_ASSERT(910, i_modify || isCurrentSolidHeap());
    JUT_ASSERT(912, i_matTable != 0 && i_brk != 0);
    mpAnm = i_brk;
    mpAnm->searchUpdateMaterialID(i_matTable);

    u16 CRegUpdateMaterialNum = mpAnm->getCRegUpdateMaterialNum();
    if (!i_modify) {
        mCRegUpdateMaterialNum = CRegUpdateMaterialNum;
        mpCRegAnm = new J3DTevColorAnm[mCRegUpdateMaterialNum];
        if (!mpCRegAnm) {
            return 0;
        }
    }
    JUT_ASSERT(926, CRegUpdateMaterialNum <= mCRegUpdateMaterialNum);
    u16 KRegUpdateMaterialNum = mpAnm->getKRegUpdateMaterialNum();
    if (!i_modify) {
        mKRegUpdateMaterialNum = KRegUpdateMaterialNum;
        mpKRegAnm = new J3DTevKColorAnm[mKRegUpdateMaterialNum];
        if (!mpKRegAnm) {
            return 0;
        }
    }
    JUT_ASSERT(937, KRegUpdateMaterialNum <= mKRegUpdateMaterialNum);

    J3DTevColorAnm* cRegAnm = mpCRegAnm;
    for (u16 i = 0; i < CRegUpdateMaterialNum; i++) {
        cRegAnm->setAnmIndex(i);
        cRegAnm->setAnmTevReg(mpAnm);
        cRegAnm++;
    }
    J3DTevKColorAnm* kRegAnm = mpKRegAnm;
    for (u16 i = 0; i < KRegUpdateMaterialNum; i++) {
        kRegAnm->setAnmIndex(i);
        kRegAnm->setAnmTevReg(mpAnm);
        kRegAnm++;
    }

    if (!i_modify && i_entry) {
        i_matTable->setTevRegAnimator(mpAnm, mpCRegAnm, mpKRegAnm);
    }

    if (i_anmPlay) {
        if (initPlay(mpAnm->getFrameMax(), i_attribute, i_rate, i_startF, i_endF, i_modify) == 0) {
            return 0;
        }
    }
    return 1;
}

/* 8000EF80-8000EFBC       .text entry__13mDoExt_brkAnmFP16J3DMaterialTablef */
void mDoExt_brkAnm::entry(J3DMaterialTable* i_matTable, f32 i_frame) {
    mpAnm->setFrame(i_frame);
    i_matTable->setTevRegAnimator(mpAnm, mpCRegAnm, mpKRegAnm);
}

/* 8000EFBC-8000F178       .text init__13mDoExt_bvaAnmFP8J3DModelP20J3DAnmVisibilityFulliifssbi */
int mDoExt_bvaAnm::init(J3DModel* i_model, J3DAnmVisibilityFull* i_bva, int i_anmPlay, int i_attribute, f32 i_rate, s16 i_startF, s16 i_endF, bool i_modify, int i_entry) {
    JUT_ASSERT(1002, i_modify || isCurrentSolidHeap());
    JUT_ASSERT(1004, i_model != 0 && i_bva != 0);
    mpAnm = i_bva;
    if (!i_modify) {
        field_0xc = new J3DVisibilityManager(mpAnm);
        if (!field_0xc) {
            return 0;
        }
        if (i_entry) {
            i_model->setVisibilityManager(field_0xc);
        }
    } else {
        field_0xc->mAnmVisibility = mpAnm;
    }
    if (i_anmPlay) {
        if (initPlay(mpAnm->getFrameMax(), i_attribute, i_rate, i_startF, i_endF, i_modify) == 0) {
            return 0;
        }
    }
    return 1;
}

/* 8000F178-8000F1B4       .text entry__13mDoExt_bvaAnmFP8J3DModels */
void mDoExt_bvaAnm::entry(J3DModel* i_model, s16 i_frame) {
    mpAnm->setFrame(i_frame);
    i_model->setVisibilityManager(field_0xc);
}

/* 8000F1B4-8000F408       .text init__13mDoExt_bckAnmFP12J3DModelDataP15J3DAnmTransformiifssb */
int mDoExt_bckAnm::init(J3DModelData* i_modelData, J3DAnmTransform* i_bck, int i_anmPlay, int i_attribute, f32 i_rate, s16 i_startF, s16 i_endF, bool i_modify) {
    JUT_ASSERT(1065, i_modify || isCurrentSolidHeap());
    JUT_ASSERT(1067, i_bck != 0);
    mAnmTransform = i_bck;
    if (!i_modify) {
        mAnm = new J3DMtxCalcMayaAnm(mAnmTransform);
        if (!mAnm) {
            return 0;
        }
    } else {
        mAnm->setAnmTransform(mAnmTransform);
    }
    if (i_anmPlay) {
        if (initPlay(mAnmTransform->getFrameMax(), i_attribute, i_rate, i_startF, i_endF, i_modify) == 0) {
            return 0;
        }
    }
    return 1;
}

/* 8000F590-8000F610       .text changeBckOnly__13mDoExt_bckAnmFP15J3DAnmTransform */
void mDoExt_bckAnm::changeBckOnly(J3DAnmTransform* i_bck) {
    mAnmTransform = i_bck;
    JUT_ASSERT(1104, mAnm != 0);
    mAnm->setAnmTransform(mAnmTransform);
}

/* 8000F610-8000F638       .text entry__13mDoExt_bckAnmFP12J3DModelDataf */
void mDoExt_bckAnm::entry(J3DModelData* i_modelData, f32 i_frame) {
    mAnmTransform->setFrame(i_frame);
    i_modelData->getJointNodePointer(0)->setMtxCalc(mAnm);
}

/* 8000F638-8000F6A0       .text mDoExt_changeMaterial__FP8J3DModel */
void mDoExt_changeMaterial(J3DModel* i_model) {
    J3DModelData* model_data = i_model->getModelData();

    for (u16 i = 0; i < model_data->getMaterialNum(); i++) {
        model_data->getMaterialNodePointer(i)->change();
    }
}

/* 8000F6A0-8000F758       .text mDoExt_modelTexturePatch__FP12J3DModelData */
void mDoExt_modelTexturePatch(J3DModelData* i_modelData) {
    j3dSys.setTexture(i_modelData->getTexture());

    for (u16 i = 0; i < i_modelData->getMaterialNum(); i++) {
        J3DMaterial* mat = i_modelData->getMaterialNodePointer(i);
        J3DTevBlock* tev = mat->getTevBlock();
        J3DDisplayListObj* dlObj = mat->getSharedDisplayListObj();

        BOOL ret = OSDisableInterrupts();
        GDInitGDLObj(&J3DDisplayListObj::sGDLObj, dlObj->getDisplayList(0),
                     dlObj->getDisplayListSize());
        GDSetCurrent(&J3DDisplayListObj::sGDLObj);
        tev->patchTexNoAndTexCoordScale();
        OSRestoreInterrupts(ret);
        GDSetCurrent(NULL);
    }
}

static void dummy(J3DTevBlock* tev, J3DColorBlock* color, J3DPEBlock* pe) {
    tev->patch();
    color->patchLight();
    pe->patch();
}

/* 8000F768-8000F7BC       .text mDoExt_modelDiff__FP8J3DModel */
void mDoExt_modelDiff(J3DModel* i_model) {
    i_model->calcMaterial();
    i_model->diff();
    i_model->entry();
}

/* 8000F7BC-8000F84C       .text mDoExt_modelUpdate__FP8J3DModel */
void mDoExt_modelUpdate(J3DModel* i_model) {
    J3DModelData* model_data = i_model->getModelData();

    if (model_data->getModelDataType() == 1 && !model_data->isLocked()) {
        i_model->calc();
        mDoExt_modelDiff(i_model);
    } else {
        i_model->update();
        i_model->lock();
    }

    i_model->viewCalc();
}

/* 8000F84C-8000F8F8       .text mDoExt_modelUpdateDL__FP8J3DModel */
void mDoExt_modelUpdateDL(J3DModel* i_model) {
    J3DModelData* model_data = i_model->getModelData();

    if (model_data->getModelDataType() == 1 && !model_data->isLocked()) {
        i_model->calc();
        mDoExt_modelDiff(i_model);
    } else {
        if (g_regHIO.mChild[2].mShortRegs[9] == 0) {
            i_model->unlock();
        }
        i_model->update();
        i_model->lock();
    }

    i_model->viewCalc();
}

/* 8000F8F8-8000F974       .text mDoExt_modelEntry__FP8J3DModel */
void mDoExt_modelEntry(J3DModel* i_model) {
    J3DModelData* model_data = i_model->getModelData();

    if (model_data->getModelDataType() == 1 && !model_data->isLocked()) {
        mDoExt_modelDiff(i_model);
    } else {
        i_model->entry();
        i_model->lock();
    }

    i_model->viewCalc();
}

/* 8000F974-8000FA0C       .text mDoExt_modelEntryDL__FP8J3DModel */
void mDoExt_modelEntryDL(J3DModel* i_model) {
    J3DModelData* model_data = i_model->getModelData();

    if (model_data->getModelDataType() == 1 && !model_data->isLocked()) {
        mDoExt_modelDiff(i_model);
    } else {
        if (g_regHIO.mChild[2].mShortRegs[9] == 0) {
            i_model->unlock();
        }
        i_model->entry();
        i_model->lock();
    }

    i_model->viewCalc();
}

/* 8000FA0C-800100F0       .text store__23mDoExt_backupMatBlock_cFP11J3DMaterial */
void mDoExt_backupMatBlock_c::store(J3DMaterial* i_material) {
    J3DColorBlock* colorBlock = i_material->getColorBlock();
    mColorChanNum = colorBlock->getColorChanNum();
    for (u32 i = 0; i < 2; i++) {
        mMatColor[i] = *colorBlock->getMatColor(i);
    }
    for (u32 i = 0; i < 4; i++) {
        mColorChan[i] = *colorBlock->getColorChan(i);
    }
    for (u32 i = 0; i < 2; i++) {
        mAmbColor[i] = *colorBlock->getAmbColor(i);
    }
    J3DTexGenBlock* texGenBlock = i_material->getTexGenBlock();
    mTexGenNum = texGenBlock->getTexGenNum();
    u32 texGenMax = 8;
    if (texGenBlock->getType() == 'TGB4') {
        texGenMax = 4;
    };
    for (u32 i = 0; i < texGenMax; i++) {
        mTexCoord[i] = *texGenBlock->getTexCoord(i);
    }
    for (u32 i = 0; i < texGenMax; i++) {
        if (texGenBlock->getTexMtx(i)) {
            memcpy(&mTexMtx[i], texGenBlock->getTexMtx(i), sizeof(J3DTexMtx));
            DCStoreRange(&mTexMtx[i], sizeof(J3DTexMtx));
        }
    }
    J3DTevBlock* tevBlock = i_material->getTevBlock();
    mTevStageNum = tevBlock->getTevStageNum();
    for (u32 i = 0; i < 4; i++) {
        mTevColor[i] = *tevBlock->getTevColor(i);
    }
    for (u32 i = 0; i < 4; i++) {
        mTevKColor[i] = *tevBlock->getTevKColor(i);
    }
    u32 texNoMax = 8;
    if (tevBlock->getType() == 'TVB4') {
        texNoMax = 4;
        for (u32 i = 0; i < 4; i++) {
            mTevOrder[i] = *tevBlock->getTevOrder(i);
            mTevKColorSel[i] = tevBlock->getTevKColorSel(i);
            mTevKAlphaSel[i] = tevBlock->getTevKAlphaSel(i);
        }
        for (u32 i = 0; i < 4; i++) {
            mTevSwapModeTable[i] = *tevBlock->getTevSwapModeTable(i);
        }
    }
    for (u32 i = 0; i < texNoMax; i++) {
        mTexNo[i] = tevBlock->getTexNo(i);
    }
    for (u32 i = 0; i < texNoMax; i++) {
        mTevStage[i] = *tevBlock->getTevStage(i);
        mIndTevStage[i] = *tevBlock->getIndTevStage(i);
    }
    J3DIndBlock* indBlock = i_material->getIndBlock();
    if (indBlock->getType() == 'IBLF') {
        mIndTexStageNum = indBlock->getIndTexStageNum();
        for (u32 i = 0; i < 4; i++) {
            mIndTexOrder[i] = *indBlock->getIndTexOrder(i);
        }
        for (u32 i = 0; i < 3; i++) {
            mIndTexMtx[i] = *indBlock->getIndTexMtx(i);
        }
        for (u32 i = 0; i < 4; i++) {
            mIndTexCoordScale[i] = *indBlock->getIndTexCoordScale(i);
        }
    }
    J3DPEBlock* peBlock = i_material->getPEBlock();
    memcpy(&mFog, peBlock->getFog(), sizeof(J3DFog));
    DCStoreRange(&mFog, sizeof(J3DFog));
    mAlphaComp = *peBlock->getAlphaComp();
    mBlend = *peBlock->getBlend();
    mZMode = *peBlock->getZMode();
    mZCompLoc = peBlock->getZCompLoc();
    mMaterialAnm = i_material->getMaterialAnm();
    mMaterialMode = i_material->getMaterialMode();
}

/* 800101BC-8001084C       .text restore__23mDoExt_backupMatBlock_cFP11J3DMaterial */
void mDoExt_backupMatBlock_c::restore(J3DMaterial* i_material) {
    /* Nonmatching */
    J3DColorBlock* colorBlock = i_material->getColorBlock();
    colorBlock->setColorChanNum(mColorChanNum);
    for (u32 i = 0; i < 2; i++) {
        colorBlock->setMatColor(i, mMatColor[i]);
    }
    for (u32 i = 0; i < 4; i++) {
        colorBlock->setColorChan(i, mColorChan[i]);
    }
    for (u32 i = 0; i < 2; i++) {
        colorBlock->setAmbColor(i, mAmbColor[i]);
    }
    J3DTexGenBlock* texGenBlock = i_material->getTexGenBlock();
    texGenBlock->setTexGenNum(mTexGenNum);
    u32 texGenMax = 8;
    if (texGenBlock->getType() == 'TGB4') {
        texGenMax = 4;
    };
    for (u32 i = 0; i < texGenMax; i++) {
        texGenBlock->setTexCoord(i, &mTexCoord[i]);
    }
    for (u32 i = 0; i < texGenMax; i++) {
        if (texGenBlock->getTexMtx(i)) {
            memcpy(texGenBlock->getTexMtx(i), &mTexMtx[i], sizeof(J3DTexMtx));
            DCStoreRange(texGenBlock->getTexMtx(i), sizeof(J3DTexMtx));
        }
    }
    J3DTevBlock* tevBlock = i_material->getTevBlock();
    tevBlock->setTevStageNum(mTevStageNum);
    for (u32 i = 0; i < 4; i++) {
        tevBlock->setTevColor(i, mTevColor[i]);
    }
    for (u32 i = 0; i < 4; i++) {
        tevBlock->setTevKColor(i, mTevKColor[i]);
    }
    u32 texNoMax = 8;
    if (tevBlock->getType() == 'TVB4') {
        texNoMax = 4;
        for (u32 i = 0; i < 4; i++) {
            tevBlock->setTevOrder(i, mTevOrder[i]);
            tevBlock->setTevKColorSel(i, mTevKColorSel[i]);
            tevBlock->setTevKAlphaSel(i, mTevKAlphaSel[i]);
        }
        for (u32 i = 0; i < 4; i++) {
            tevBlock->setTevSwapModeTable(i, mTevSwapModeTable[i]);
        }
    }
    for (u32 i = 0; i < texNoMax; i++) {
        tevBlock->setTexNo(i, mTexNo[i]);
    }
    for (u32 i = 0; i < texNoMax; i++) {
        tevBlock->setTevStage(i, mTevStage[i]);
        tevBlock->setIndTevStage(i, mIndTevStage[i]);
    }
    J3DIndBlock* indBlock = i_material->getIndBlock();
    if (indBlock->getType() == 'IBLF') {
        indBlock->setIndTexStageNum(mIndTexStageNum);
        for (u32 i = 0; i < 4; i++) {
            *indBlock->getIndTexOrder(i) = mIndTexOrder[i];
        }
        for (u32 i = 0; i < 3; i++) {
            indBlock->setIndTexMtx(i, mIndTexMtx[i]);
        }
        for (u32 i = 0; i < 4; i++) {
            indBlock->setIndTexCoordScale(i, mIndTexCoordScale[i]);
        }
    }
    J3DPEBlock* peBlock = i_material->getPEBlock();
    memcpy(peBlock->getFog(), &mFog, sizeof(J3DFog));
    DCStoreRange(peBlock->getFog(), sizeof(J3DFog));
    peBlock->setAlphaComp(mAlphaComp);
    peBlock->setBlend(mBlend);
    peBlock->setZMode(mZMode);
    peBlock->setZCompLoc(mZCompLoc);
    i_material->setMaterialAnm(mMaterialAnm);
    i_material->setMaterialMode(mMaterialMode);
}

/* 80010920-800109F4       .text create__23mDoExt_backupMaterial_cFP12J3DModelData */
bool mDoExt_backupMaterial_c::create(J3DModelData* i_modelData) {
    if (!mBackupMatBlock) {
        mBackupMatBlock = new mDoExt_backupMatBlock_c[i_modelData->getMaterialNum()];
        if (!mBackupMatBlock) {
            return false;
        }
    }
    for (u16 i = 0; i < i_modelData->getMaterialNum(); i++) {
        J3DMaterial* material = i_modelData->getMaterialNodePointer(i);
        mBackupMatBlock[i].store(material);
    }
    mTexture = i_modelData->getTexture();
    mTextureName = i_modelData->getTextureName();
    return true;
}

/* 800109F4-80010A88       .text __dt__23mDoExt_backupMatBlock_cFv */
mDoExt_backupMatBlock_c::~mDoExt_backupMatBlock_c() {}

/* 80010AC4-80010D44       .text __ct__23mDoExt_backupMatBlock_cFv */
mDoExt_backupMatBlock_c::mDoExt_backupMatBlock_c() {
    /* Nonmatching */
}

/* 80011294-80011300       .text create__23mDoExt_backupMaterial_cFUs */
bool mDoExt_backupMaterial_c::create(u16 param_0) {
    mBackupMatBlock = new mDoExt_backupMatBlock_c[param_0];
    return mBackupMatBlock != NULL;
}

/* 80011300-80011380       .text restore__23mDoExt_backupMaterial_cFP12J3DModelData */
void mDoExt_backupMaterial_c::restore(J3DModelData* i_modelData) {
    for (u16 i = 0; i < i_modelData->getMaterialNum(); i++) {
        J3DMaterial* material = i_modelData->getMaterialNodePointer(i);
        mBackupMatBlock[i].restore(material);
    }
    i_modelData->setTexture(mTexture);
    i_modelData->setTextureName(mTextureName);
}

/* 80011380-80011434       .text create__21mDoExt_invisibleModelFP8J3DModel */
BOOL mDoExt_invisibleModel::create(J3DModel* model) {
    J3DModelData* modelData = model->getModelData();

    mpPackets = new mDoExt_invJntPacket[modelData->getJointNum()];
    if (!mpPackets) {
        return false;
    }

    mModel = model;
    mDoExt_invJntPacket* packet = mpPackets;

    for (u16 i = 0; i < modelData->getJointNum(); i++) {
        packet->setJoint(mModel, i);
        packet++;
    }

    return true;
}

/* 80011504-800115AC       .text entry__21mDoExt_invisibleModelFv */
void mDoExt_invisibleModel::entry() {
    J3DModelData* modelData = mModel->getModelData();
    mDoExt_invJntPacket* packet = mpPackets;

    cXyz tmp;
    for (u16 i = 0; i < modelData->getJointNum(); i++) {
        MtxP anmMtx = mModel->getAnmMtx(i);
        tmp.set(anmMtx[0][3], anmMtx[1][3], anmMtx[2][3]);
        dComIfGd_entryZSortXluList(packet, tmp);
        packet++;
    }
}

/* 800115AC-80011654       .text entryMaskOff__21mDoExt_invisibleModelFv */
void mDoExt_invisibleModel::entryMaskOff() {
    J3DModelData* modelData = mModel->getModelData();
    mDoExt_invJntPacket* packet = mpPackets;

    cXyz tmp;
    for (u16 i = 0; i < modelData->getJointNum(); i++) {
        MtxP anmMtx = mModel->getAnmMtx(i);
        tmp.set(anmMtx[0][3], anmMtx[1][3], anmMtx[2][3]);
        dComIfGd_entryZSortXluListMaskOff(packet, tmp);
        packet++;
    }
}

/* 80011654-800116C4       .text updateDL__21mDoExt_invisibleModelFP8J3DModel */
void mDoExt_invisibleModel::updateDL(J3DModel* model) {
    J3DDrawBuffer* buffer0 = j3dSys.getDrawBuffer(0);
    J3DDrawBuffer* buffer1 = j3dSys.getDrawBuffer(1);
    dComIfGd_setList();
    mDoExt_modelUpdateDL(model);
    entry();
    j3dSys.setDrawBuffer(buffer0, 0);
    j3dSys.setDrawBuffer(buffer1, 1);
}

/* 800116C4-80011734       .text updateDL__21mDoExt_invisibleModelFP14mDoExt_McaMorf */
void mDoExt_invisibleModel::updateDL(mDoExt_McaMorf* param_0) {
    J3DDrawBuffer* buffer0 = j3dSys.getDrawBuffer(0);
    J3DDrawBuffer* buffer1 = j3dSys.getDrawBuffer(1);
    dComIfGd_setList();
    param_0->updateDL();
    entry();
    j3dSys.setDrawBuffer(buffer0, 0);
    j3dSys.setDrawBuffer(buffer1, 1);
}

JKRExpHeap* gameHeap;

/* 80011734-800117E4       .text mDoExt_createGameHeap__FUlP7JKRHeap */
JKRExpHeap* mDoExt_createGameHeap(u32 heapSize, JKRHeap* i_heap) {
    JUT_ASSERT(2050, gameHeap == 0 || heapSize == 0);
    gameHeap = JKRExpHeap::create(heapSize, i_heap, true);
    gameHeap->setAllocationMode(JKRExpHeap::ALLOC_MODE_1);
    return gameHeap;
}

/* 800117E4-800117EC       .text mDoExt_getGameHeap__Fv */
JKRExpHeap* mDoExt_getGameHeap() {
    return gameHeap;
}

s32 safeGameHeapSize;

/* 800117EC-80011814       .text mDoExt_setSafeGameHeapSize__Fv */
void mDoExt_setSafeGameHeapSize() {
    safeGameHeapSize = mDoExt_getGameHeap()->getTotalFreeSize();
}

/* 80011814-8001181C       .text mDoExt_getSafeGameHeapSize__Fv */
s32 mDoExt_getSafeGameHeapSize() {
    return safeGameHeapSize;
}

JKRExpHeap* zeldaHeap;

/* 8001181C-800118C0       .text mDoExt_createZeldaHeap__FUlP7JKRHeap */
JKRExpHeap* mDoExt_createZeldaHeap(u32 heapSize, JKRHeap* i_heap) {
    JUT_ASSERT(2112, zeldaHeap == 0 || heapSize == 0);
    return zeldaHeap = JKRExpHeap::create(heapSize, i_heap, true);
}

/* 800118C0-800118C8       .text mDoExt_getZeldaHeap__Fv */
JKRExpHeap* mDoExt_getZeldaHeap() {
    return zeldaHeap;
}

s32 safeZeldaHeapSize;

/* 800118C8-800118F0       .text mDoExt_setSafeZeldaHeapSize__Fv */
void mDoExt_setSafeZeldaHeapSize() {
    safeZeldaHeapSize = mDoExt_getZeldaHeap()->getTotalFreeSize();
}

/* 800118F0-800118F8       .text mDoExt_getSafeZeldaHeapSize__Fv */
s32 mDoExt_getSafeZeldaHeapSize() {
    return safeZeldaHeapSize;
}

JKRExpHeap* commandHeap;

/* 800118F8-8001199C       .text mDoExt_createCommandHeap__FUlP7JKRHeap */
JKRExpHeap* mDoExt_createCommandHeap(u32 heapSize, JKRHeap* i_heap) {
    JUT_ASSERT(2173, commandHeap == 0 || heapSize == 0);
    return commandHeap = JKRExpHeap::create(heapSize, i_heap, true);
}

/* 8001199C-800119A4       .text mDoExt_getCommandHeap__Fv */
JKRExpHeap* mDoExt_getCommandHeap() {
    return commandHeap;
}

s32 safeCommandHeapSize;

/* 800119A4-800119CC       .text mDoExt_setSafeCommandHeapSize__Fv */
void mDoExt_setSafeCommandHeapSize() {
    safeCommandHeapSize = mDoExt_getCommandHeap()->getTotalFreeSize();
}

/* 800119CC-800119D4       .text mDoExt_getSafeCommandHeapSize__Fv */
s32 mDoExt_getSafeCommandHeapSize() {
    return safeCommandHeapSize;
}

JKRExpHeap* archiveHeap;

/* 800119D4-80011A84       .text mDoExt_createArchiveHeap__FUlP7JKRHeap */
JKRExpHeap* mDoExt_createArchiveHeap(u32 heapSize, JKRHeap* i_heap) {
    JUT_ASSERT(2237, archiveHeap == 0 || heapSize == 0);
    archiveHeap = JKRExpHeap::create(heapSize, i_heap, true);
    archiveHeap->setAllocationMode(JKRExpHeap::ALLOC_MODE_1);
    return archiveHeap;
}

s32 safeArchiveHeapSize;

/* 80011A84-80011AAC       .text mDoExt_setSafeArchiveHeapSize__Fv */
void mDoExt_setSafeArchiveHeapSize() {
    safeArchiveHeapSize = mDoExt_getArchiveHeap()->getTotalFreeSize();
}

/* 80011AAC-80011AB4       .text mDoExt_getSafeArchiveHeapSize__Fv */
s32 mDoExt_getSafeArchiveHeapSize() {
    return safeArchiveHeapSize;
}

/* 80011AB4-80011ABC       .text mDoExt_getArchiveHeap__Fv */
JKRExpHeap* mDoExt_getArchiveHeap() {
    return archiveHeap;
}

/* 80011ABC-80011B54       .text mDoExt_createSolidHeap__FUlP7JKRHeapUl */
JKRSolidHeap* mDoExt_createSolidHeap(u32 i_size, JKRHeap* i_heap, u32 i_alignment) {
    if (i_heap == NULL) {
        i_heap = JKRHeap::getCurrentHeap();
    }

    JKRSolidHeap* createdHeap;
    if (i_size == 0 || i_size == 0xFFFFFFFF) {
        createdHeap = JKRSolidHeap::create(0xFFFFFFFFFF, i_heap, false);
    } else {
        i_size = ALIGN_NEXT(i_size, 0x10);
        i_size += 0x80;

        if (0x10 < i_alignment) {
            i_size = (i_alignment - 0x10 + i_size);
        }
        createdHeap = JKRSolidHeap::create(i_size, i_heap, false);
    }

    if (createdHeap != NULL) {
        createdHeap->setErrorFlag(true);
    }

    return createdHeap;
}

/* 80011B54-80011B9C       .text mDoExt_createSolidHeapFromGame__FUlUl */
JKRSolidHeap* mDoExt_createSolidHeapFromGame(u32 i_size, u32 i_alignment) {
    return mDoExt_createSolidHeap(i_size, mDoExt_getGameHeap(), i_alignment);
}

/* 80011B9C-80011BE4       .text mDoExt_createSolidHeapFromSystem__FUlUl */
JKRSolidHeap* mDoExt_createSolidHeapFromSystem(u32 i_size, u32 i_alignment) {
    return mDoExt_createSolidHeap(i_size, mDoExt_getZeldaHeap(), i_alignment);
}

static void dummy() {
    OSReport("situationHeap == 0 || heapSize == 0");
    OSReport("situationHeapLocked == 0");
    OSReport("situationHeap");
    OSReport("situationHeapLocked");
    OSReport("heap == situationHeap");
}

JKRHeap* mDoExt_SaveCurrentHeap;

/* 80011BE4-80011CC0       .text mDoExt_createSolidHeapToCurrent__FUlP7JKRHeapUl */
JKRSolidHeap* mDoExt_createSolidHeapToCurrent(u32 i_size, JKRHeap* i_parent, u32 i_alignment) {
    JKRSolidHeap* resultHeap = mDoExt_createSolidHeap(i_size, i_parent, i_alignment);
    if (!resultHeap) {
        return NULL;
    }
    JUT_ASSERT(2545, OSGetCurrentThread() == &mainThread);
    JUT_ASSERT(2546, mDoExt_SaveCurrentHeap == 0);
    mDoExt_SaveCurrentHeap = JKRGetCurrentHeap();
    mDoExt_setCurrentHeap(resultHeap);

    return resultHeap;
}

/* 80011CC0-80011D0C       .text mDoExt_createSolidHeapFromGameToCurrent__FUlUl */
JKRSolidHeap* mDoExt_createSolidHeapFromGameToCurrent(u32 i_size, u32 i_alignment) {
    mDoExt_getGameHeap();
    return mDoExt_createSolidHeapToCurrent(i_size, mDoExt_getGameHeap(), i_alignment);
}

/* 80011D0C-80011D48       .text mDoExt_adjustSolidHeap__FP12JKRSolidHeap */
s32 mDoExt_adjustSolidHeap(JKRSolidHeap* i_heap) {
    if (i_heap == NULL)
        return 0;

    s32 result = i_heap->adjustSize();
    if (result >= 0x80u)
        result -= 0x80;

    return result;
}

/* 80011D48-80011D68       .text mDoExt_destroySolidHeap__FP12JKRSolidHeap */
void mDoExt_destroySolidHeap(JKRSolidHeap* i_heap) {
    i_heap->destroy();
}

/* 80011D68-80011DD4       .text mDoExt_setCurrentHeap__FP7JKRHeap */
JKRHeap* mDoExt_setCurrentHeap(JKRHeap* heap) {
    JUT_ASSERT(2684, heap != 0);
    return heap->becomeCurrentHeap();
}

/* 80011DD4-80011DDC       .text mDoExt_getCurrentHeap__Fv */
JKRHeap* mDoExt_getCurrentHeap() {
    return JKRGetCurrentHeap();
}

/* 80011DDC-80011E98       .text mDoExt_restoreCurrentHeap__Fv */
void mDoExt_restoreCurrentHeap() {
    JUT_ASSERT(2754, OSGetCurrentThread() == &mainThread);
    JUT_ASSERT(2755, mDoExt_SaveCurrentHeap != 0);
    mDoExt_SaveCurrentHeap->becomeCurrentHeap();
    mDoExt_SaveCurrentHeap = NULL;
}

/* 80011E98-80011EE4       .text mDoExt_resIDToIndex__FP10JKRArchiveUs */
s32 mDoExt_resIDToIndex(JKRArchive* p_archive, u16 id) {
    JKRArchive::SDIFileEntry* res = p_archive->findIdResource(id);

    if (res == NULL) {
        return -1;
    }

    return res - p_archive->mFiles;
}

/* 80011EE4-80012140       .text calc__25mDoExt_MtxCalcAnmBlendTblFUs */
void mDoExt_MtxCalcAnmBlendTbl::calc(u16 param_0) {
    j3dSys.setCurrentMtxCalc(this);
    if (mNum == 1) {
        J3DTransformInfo info1;
        mAnmRatio->getAnmTransform()->getTransform(param_0, &info1);
        calcTransform(param_0, info1);
        return;
    }
    J3DTransformInfo info2;
    Quaternion quat1;
    Quaternion quat2;
    Quaternion quat3;
    mAnmRatio->getAnmTransform()->getTransform(param_0, &info2);
    JMAEulerToQuat(info2.mRotation.x, info2.mRotation.y, info2.mRotation.z, &quat1);
    quat3 = quat1;
    for (int i = 1; i < mNum; i++) {
        J3DAnmTransform* transform = mAnmRatio[i].getAnmTransform();
        if (transform) {
            J3DTransformInfo info3;
            transform->getTransform(param_0, &info3);
            f32 ratio = mAnmRatio[i].getRatio();
            f32 f30 = 1.0f - ratio;
            JMAEulerToQuat(info3.mRotation.x, info3.mRotation.y, info3.mRotation.z, &quat2);
            JMAQuatLerp(&quat1, &quat2, ratio, &quat3);
            quat1 = quat3;
            info2.mTranslate.x = info2.mTranslate.x * f30 + info3.mTranslate.x * ratio;
            info2.mTranslate.y = info2.mTranslate.y * f30 + info3.mTranslate.y * ratio;
            info2.mTranslate.z = info2.mTranslate.z * f30 + info3.mTranslate.z * ratio;
            info2.mScale.x = info2.mScale.x * f30 + info3.mScale.x * ratio;
            info2.mScale.y = info2.mScale.y * f30 + info3.mScale.y * ratio;
            info2.mScale.z = info2.mScale.z * f30 + info3.mScale.z * ratio;
        }
    }
    Mtx mtx;
    MTXQuat(mtx, &quat3);
    mDoExt_setJ3DData(mtx, &info2, param_0);
}

/* 80012140-80012548       .text calc__28mDoExt_MtxCalcAnmBlendTblOldFUs */
void mDoExt_MtxCalcAnmBlendTblOld::calc(u16 param_0) {
    j3dSys.setCurrentMtxCalc(this);
    J3DTransformInfo info1;
    Quaternion quat1;
    Quaternion quat2;
    Quaternion quat3;
    mAnmRatio->getAnmTransform()->getTransform(param_0, &info1);
    JMAEulerToQuat(info1.mRotation.x, info1.mRotation.y, info1.mRotation.z, &quat1);
    quat3 = quat1;
    for (int i = 1; i < mNum; i++) {
        if (mAnmRatio[i].getAnmTransform()) {
            J3DAnmTransform* transform = mAnmRatio[i].getAnmTransform();
            J3DTransformInfo info2;
            transform->getTransform(param_0, &info2);
            f32 ratio = mAnmRatio[i].getRatio();
            f32 f30 = 1.0f - ratio;
            JMAEulerToQuat(info2.mRotation.x, info2.mRotation.y, info2.mRotation.z, &quat2);
            JMAQuatLerp(&quat1, &quat2, ratio, &quat3);
            quat1 = quat3;
            info1.mTranslate.x = info1.mTranslate.x * f30 + info2.mTranslate.x * ratio;
            info1.mTranslate.y = info1.mTranslate.y * f30 + info2.mTranslate.y * ratio;
            info1.mTranslate.z = info1.mTranslate.z * f30 + info2.mTranslate.z * ratio;
            info1.mScale.x = info1.mScale.x * f30 + info2.mScale.x * ratio;
            info1.mScale.y = info1.mScale.y * f30 + info2.mScale.y * ratio;
            info1.mScale.z = info1.mScale.z * f30 + info2.mScale.z * ratio;
        }
    }

    J3DModel* model = j3dSys.getModel();
    J3DTransformInfo* oldTransInfo = mOldFrame->getOldFrameTransInfo(param_0);
    Quaternion* oldQuat = mOldFrame->getOldFrameQuaternion(param_0);
    if (mOldFrame->getOldFrameFlg()) {
        if (mOldFrame->getOldFrameRate() > 0.0f && mOldFrame->getOldFrameStartJoint() <= param_0 && mOldFrame->getOldFrameEndJoint() > param_0) {
            f32 oldFrameRate = mOldFrame->getOldFrameRate();
            f32 f31 = 1.0f - oldFrameRate;
            JMAQuatLerp(oldQuat, &quat1, f31, &quat3);
            info1.mTranslate.x = info1.mTranslate.x * f31 + oldTransInfo->mTranslate.x * oldFrameRate;
            info1.mTranslate.y = info1.mTranslate.y * f31 + oldTransInfo->mTranslate.y * oldFrameRate;
            info1.mTranslate.z = info1.mTranslate.z * f31 + oldTransInfo->mTranslate.z * oldFrameRate;
            info1.mScale.x = info1.mScale.x * f31 + oldTransInfo->mScale.x * oldFrameRate;
            info1.mScale.y = info1.mScale.y * f31 + oldTransInfo->mScale.y * oldFrameRate;
            info1.mScale.z = info1.mScale.z * f31 + oldTransInfo->mScale.z * oldFrameRate;
        }
    } else if (param_0 == model->getModelData()->getJointNum() - 1) {
        mOldFrame->onOldFrameFlg();
    }
    Mtx mtx;
    if (mBeforeCallback) {
        mBeforeCallback(field_0x58, param_0, &info1, &quat3);
    }
    mDoMtx_quat(mtx, &quat3);
    mDoExt_setJ3DData(mtx, &info1, param_0);
    if (mAfterCallback) {
        mAfterCallback(field_0x58, param_0, &info1, &quat3);
    }
    *oldQuat = quat3;
    *oldTransInfo = info1;
    if (param_0 == model->getModelData()->getJointNum() - 1) {
        mOldFrame->decOldFrameMorfCounter();
    }
}

/* 80012548-800125CC       .text initOldFrameMorf__22mDoExt_MtxCalcOldFrameFfUsUs */
void mDoExt_MtxCalcOldFrame::initOldFrameMorf(f32 param_0, u16 param_1, u16 param_2) {
    if (param_0 > 0.0f) {
        mOldFrameMorfCounter = param_0;
        field_0x8 = 1.0f / param_0;
        mOldFrameRate = 1.0f;
        field_0x10 = 1.0f;
        field_0x14 = 1.0f;
        decOldFrameMorfCounter();
    } else {
        mOldFrameMorfCounter = 0.0f;
        field_0x8 = 0.0f;
        mOldFrameRate = 0.0f;
        field_0x10 = 0.0f;
        field_0x14 = 0.0f;
    }
    mOldFrameStartJoint = param_1;
    mOldFrameEndJoint = param_2;
}

/* 800125CC-80012650       .text decOldFrameMorfCounter__22mDoExt_MtxCalcOldFrameFv */
void mDoExt_MtxCalcOldFrame::decOldFrameMorfCounter() {
    if (!(mOldFrameMorfCounter > 0.0f)) {
        return;
    }
    mOldFrameMorfCounter -= 1.0f;
    if (mOldFrameMorfCounter <= 0.0f) {
        mOldFrameMorfCounter = 0.0f;
        field_0x8 = 0.0f;
        mOldFrameRate = 0.0f;
    }
    field_0x14 = field_0x10;
    field_0x10 = mOldFrameMorfCounter * field_0x8;
    if (field_0x14 > 0.0f) {
        mOldFrameRate = 1.0f - (field_0x14 - field_0x10) / field_0x14;
        return;
    }
    mOldFrameRate = 0.0f;
}

/* 80012650-800129E4       .text __ct__14mDoExt_McaMorfFP12J3DModelDataP25mDoExt_McaMorfCallBack1_cP25mDoExt_McaMorfCallBack2_cP15J3DAnmTransformifiiiPvUlUl */
mDoExt_McaMorf::mDoExt_McaMorf(J3DModelData* modelData, mDoExt_McaMorfCallBack1_c* callback1, mDoExt_McaMorfCallBack2_c* callback2, J3DAnmTransform* anmTransform, int loopMode, f32 param_5, int param_6, int param_7, int param_8, void* basAnm, u32 modelFlag, u32 differedDlistFlag) {
    mpModel = NULL;
    mpSound = NULL;
    mpTransformInfo = NULL;
    mpQuat = NULL;
    if (!modelData) {
        return;
    }
    if (modelData->getModelDataType() == 1 && modelFlag == 0) {
        if (modelFlag = modelData->isLocked()) {
            modelFlag = 0x20000;
        } else {
            modelFlag = 0x80000;
        }
    }
    mpModel = mDoExt_J3DModel__create(modelData, modelFlag, differedDlistFlag);
    if (!mpModel) {
        return;
    }
    if (modelFlag != 0x80000) {
        mDoExt_changeMaterial(mpModel);
    }
    if (basAnm == NULL && anmTransform) {
        basAnm = ((mDoExt_transAnmBas*)anmTransform)->getBas();
        if (basAnm) {
            param_8 = 1;
        }
    }
    if (param_8) {
        mpSound = new mDoExt_zelAnime();
        if (!mpSound) {
            goto cleanup;
        }
    }
    setAnm(anmTransform, loopMode, 0.0f, param_5, param_6, param_7, basAnm);
    mPrevMorf = -1.0f;
    mpTransformInfo = new J3DTransformInfo[modelData->getJointNum()];
    if (!mpTransformInfo) {
        goto cleanup;
    }
    mpQuat = new Quaternion[modelData->getJointNum()];
    if (mpQuat) {
        J3DTransformInfo* info = mpTransformInfo;
        Quaternion* quat = mpQuat;
        J3DModelData* r23 = mpModel->getModelData();
        u16 jointNum = r23->getJointNum();
        for (int i = 0; i < jointNum; i++) {
            *info = r23->getJointNodePointer(i)->getTransformInfo();
            JMAEulerToQuat(info->mRotation.x, info->mRotation.y, info->mRotation.z, quat);
            info++;
            quat++;
        }
        mpCallback1 = callback1;
        mpCallback2 = callback2;
        return;
    }
    
cleanup:
    if (mpSound) {
        mpSound->stop();
        mpSound = NULL;
    }
    if (mpTransformInfo) {
        mpTransformInfo = NULL;
    }
    if (mpQuat) {
        mpQuat = NULL;
    }
    if (mpModel) {
        mpModel = NULL;
    }
    return;
}

/* 80012A2C-80012D78       .text calc__14mDoExt_McaMorfFUs */
void mDoExt_McaMorf::calc(u16 param_0) {
    if (!mpModel) {
        return;
    }
    j3dSys.setCurrentMtxCalc(this);
    J3DTransformInfo info1;
    J3DTransformInfo* infoPtr;
    if (mpTransformInfo == NULL) {
        infoPtr = &info1;
    } else {
        infoPtr = &mpTransformInfo[param_0];
    }
    Quaternion quat1;
    Quaternion* quatPtr;
    if (mpQuat == NULL) {
        quatPtr = &quat1;
    } else {
        quatPtr = &mpQuat[param_0];
    }
    if (!mpAnm) {
        *infoPtr = mpModel->getModelData()->getJointNodePointer(param_0)->getTransformInfo();
        if (mpCallback1) {
            mpCallback1->execute(param_0, infoPtr);
        }
        JMAEulerToQuat(infoPtr->mRotation.x, infoPtr->mRotation.y, infoPtr->mRotation.z, quatPtr);
        calcTransform(param_0, *infoPtr);
    } else if (mCurMorf >= 1.0f || !mpTransformInfo || !mpQuat) {
        mpAnm->getTransform(param_0, infoPtr);
        if (mpCallback1) {
            mpCallback1->execute(param_0, infoPtr);
        }
        JMAEulerToQuat(infoPtr->mRotation.x, infoPtr->mRotation.y, infoPtr->mRotation.z, quatPtr);
        calcTransform(param_0, *infoPtr);
    } else {
        f32 f31 = (mCurMorf - mPrevMorf) / (1.0f - mPrevMorf);
        f32 f30 = 1.0f - f31;
        J3DTransformInfo info2;
        Quaternion quat2;
        mpAnm->getTransform(param_0, &info2);
        if (mpCallback1) {
            mpCallback1->execute(param_0, &info2);
        }
        JMAEulerToQuat(info2.mRotation.x, info2.mRotation.y, info2.mRotation.z, &quat2);
        JMAQuatLerp(quatPtr, &quat2, f31, quatPtr);
        Mtx mtx;
        mDoMtx_quat(mtx, quatPtr);
        infoPtr->mTranslate.x = infoPtr->mTranslate.x * f30 + info2.mTranslate.x * f31;
        infoPtr->mTranslate.y = infoPtr->mTranslate.y * f30 + info2.mTranslate.y * f31;
        infoPtr->mTranslate.z = infoPtr->mTranslate.z * f30 + info2.mTranslate.z * f31;
        infoPtr->mScale.x = infoPtr->mScale.x * f30 + info2.mScale.x * f31;
        infoPtr->mScale.y = infoPtr->mScale.y * f30 + info2.mScale.y * f31;
        infoPtr->mScale.z = infoPtr->mScale.z * f30 + info2.mScale.z * f31;
        mDoExt_setJ3DData(mtx, infoPtr, param_0);
    }
    if (mpCallback2) {
        mpCallback2->execute(param_0);
    }
}

/* 80012D78-80012FC8       .text setAnm__14mDoExt_McaMorfFP15J3DAnmTransformiffffPv */
void mDoExt_McaMorf::setAnm(J3DAnmTransform* bckAnm, int loopMode, f32 morf, f32 playSpeed, f32 startFrame, f32 endFrame, void* basAnm) {
    mpAnm = bckAnm;
    setStartFrame(startFrame);
    if (endFrame < 0.0f) {
        if (!mpAnm) {
            mFrameCtrl.init(0);
        } else {
            mFrameCtrl.init(mpAnm->getFrameMax());
        }
    } else {
        mFrameCtrl.init(endFrame);
    }
    if (bckAnm && loopMode < 0) {
        loopMode = bckAnm->getAttribute();
    }
    setPlayMode(loopMode);
    setPlaySpeed(playSpeed);
    if (playSpeed >= 0.0f) {
        setFrame(startFrame);
    } else {
        setFrame(getEndFrame());
    }
    setLoopFrame(getFrame());
    setMorf(morf);
    if (mpSound) {
        if (basAnm == NULL && bckAnm) {
            basAnm = ((mDoExt_transAnmBas*)bckAnm)->getBas();
        }
        mpSound->mpBasAnm = basAnm;
        if (mpSound->mpBasAnm) {
            mpSound->initActorAnimSound(basAnm, getPlaySpeed() >= 0.0f ? 1 : -1, getLoopFrame());
        } else {
            mpSound->stop();
        }
    }
}

/* 80012FC8-8001300C       .text setMorf__14mDoExt_McaMorfFf */
void mDoExt_McaMorf::setMorf(f32 param_0) {
    if (mPrevMorf < 0.0f || param_0 <= 0.0f) {
        mCurMorf = 1.0f;
    } else {
        mCurMorf = 0.0f;
        mMorfStep = 1.0f / param_0;
    }
    mPrevMorf = mCurMorf;
}

/* 8001300C-800130D0       .text play__14mDoExt_McaMorfFP3VecUlSc */
bool mDoExt_McaMorf::play(Vec*, u32, s8) {
    /* Nonmatching */
}

/* 800130D0-8001314C       .text update__14mDoExt_McaMorfFv */
void mDoExt_McaMorf::update() {
    /* Nonmatching */
}

/* 8001314C-800131C8       .text updateDL__14mDoExt_McaMorfFv */
void mDoExt_McaMorf::updateDL() {
    /* Nonmatching */
}

/* 800131C8-8001322C       .text updateDL__14mDoExt_McaMorfFP16J3DMaterialTable */
void mDoExt_McaMorf::updateDL(J3DMaterialTable*) {
    /* Nonmatching */
}

/* 8001322C-80013258       .text entry__14mDoExt_McaMorfFv */
void mDoExt_McaMorf::entry() {
    /* Nonmatching */
}

/* 80013258-80013284       .text entryDL__14mDoExt_McaMorfFv */
void mDoExt_McaMorf::entryDL() {
    /* Nonmatching */
}

/* 80013284-800132E8       .text entryDL__14mDoExt_McaMorfFP16J3DMaterialTable */
void mDoExt_McaMorf::entryDL(J3DMaterialTable*) {
    /* Nonmatching */
}

/* 800132E8-8001335C       .text calc__14mDoExt_McaMorfFv */
void mDoExt_McaMorf::calc() {
    /* Nonmatching */
}

/* 8001335C-80013388       .text stopZelAnime__14mDoExt_McaMorfFv */
void mDoExt_McaMorf::stopZelAnime() {
    /* Nonmatching */
}

/* 80013388-800136F4       .text __ct__15mDoExt_McaMorf2FP12J3DModelDataP25mDoExt_McaMorfCallBack1_cP25mDoExt_McaMorfCallBack2_cP15J3DAnmTransformP15J3DAnmTransformifiiiPvUlUl */
mDoExt_McaMorf2::mDoExt_McaMorf2(J3DModelData*, mDoExt_McaMorfCallBack1_c*, mDoExt_McaMorfCallBack2_c*, J3DAnmTransform*, J3DAnmTransform*, int, f32, int, int, int, void*, u32, u32) {
    /* Nonmatching */
}

/* 800136F4-80013770       .text ERROR_EXIT__15mDoExt_McaMorf2Fv */
void mDoExt_McaMorf2::ERROR_EXIT() {
    /* Nonmatching */
}

/* 80013770-80013E50       .text calc__15mDoExt_McaMorf2FUs */
void mDoExt_McaMorf2::calc(u16) {
    /* Nonmatching */
}

/* 80013E50-800140A0       .text setAnm__15mDoExt_McaMorf2FP15J3DAnmTransformP15J3DAnmTransformfiffffPv */
void mDoExt_McaMorf2::setAnm(J3DAnmTransform*, J3DAnmTransform*, f32, int, f32, f32, f32, f32, void*) {
    /* Nonmatching */
}

/* 800140A0-800140D8       .text setMorf__15mDoExt_McaMorf2Ff */
void mDoExt_McaMorf2::setMorf(f32) {
    /* Nonmatching */
}

/* 800140D8-8001419C       .text play__15mDoExt_McaMorf2FP3VecUlSc */
void mDoExt_McaMorf2::play(Vec*, u32, s8) {
    /* Nonmatching */
}

/* 8001419C-800141C8       .text entryDL__15mDoExt_McaMorf2Fv */
void mDoExt_McaMorf2::entryDL() {
    /* Nonmatching */
}

/* 800141C8-80014250       .text calc__15mDoExt_McaMorf2Fv */
void mDoExt_McaMorf2::calc() {
    /* Nonmatching */
}

/* 80014250-8001427C       .text stopZelAnime__15mDoExt_McaMorf2Fv */
void mDoExt_McaMorf2::stopZelAnime() {
    /* Nonmatching */
}

/* 8001427C-800142B8       .text draw__24mDoExt_offCupOnAupPacketFv */
void mDoExt_offCupOnAupPacket::draw() {
    /* Nonmatching */
}

/* 800142B8-800142F4       .text draw__24mDoExt_onCupOffAupPacketFv */
void mDoExt_onCupOffAupPacket::draw() {
    /* Nonmatching */
}

/* 800142F4-800143B8       .text draw__19mDoExt_invJntPacketFv */
void mDoExt_invJntPacket::draw() {
    /* Nonmatching */
}

/* 800143B8-80014580       .text init__15mDoExt_3Dline_cFUsii */
int mDoExt_3Dline_c::init(u16, int, int) {
    /* Nonmatching */
}

/* 80014584-80014664       .text init__19mDoExt_3DlineMat0_cFUsUsi */
int mDoExt_3DlineMat0_c::init(u16, u16, int) {
    /* Nonmatching */
}

/* 80014664-800146A0       .text __dt__15mDoExt_3Dline_cFv */
mDoExt_3Dline_c::~mDoExt_3Dline_c() {
    /* Nonmatching */
}

/* 800146A0-800146A4       .text __ct__15mDoExt_3Dline_cFv */
mDoExt_3Dline_c::mDoExt_3Dline_c() {
    /* Nonmatching */
}

/* 800146A4-80014798       .text setMaterial__19mDoExt_3DlineMat0_cFv */
void mDoExt_3DlineMat0_c::setMaterial() {
    /* Nonmatching */
}

/* 80014798-800148B4       .text draw__19mDoExt_3DlineMat0_cFv */
void mDoExt_3DlineMat0_c::draw() {
    /* Nonmatching */
}

/* 800148B4-80014E04       .text update__19mDoExt_3DlineMat0_cFUsfR8_GXColorUsP12dKy_tevstr_c */
void mDoExt_3DlineMat0_c::update(u16, f32, GXColor&, u16, dKy_tevstr_c*) {
    /* Nonmatching */
}

/* 80014E04-80015328       .text update__19mDoExt_3DlineMat0_cFUsR8_GXColorP12dKy_tevstr_c */
void mDoExt_3DlineMat0_c::update(u16, GXColor&, dKy_tevstr_c*) {
    /* Nonmatching */
}

/* 80015328-800154C4       .text init__19mDoExt_3DlineMat1_cFUsUsP7ResTIMGi */
int mDoExt_3DlineMat1_c::init(u16, u16, ResTIMG*, int) {
    /* Nonmatching */
}

/* 800154C4-800155DC       .text setMaterial__19mDoExt_3DlineMat1_cFv */
void mDoExt_3DlineMat1_c::setMaterial() {
    /* Nonmatching */
}

/* 800155DC-80015764       .text draw__19mDoExt_3DlineMat1_cFv */
void mDoExt_3DlineMat1_c::draw() {
    /* Nonmatching */
}

/* 80015764-80015E54       .text update__19mDoExt_3DlineMat1_cFUsfR8_GXColorUsP12dKy_tevstr_c */
void mDoExt_3DlineMat1_c::update(u16, f32, _GXColor&, u16, dKy_tevstr_c*) {
    /* Nonmatching */
}

/* 80015E54-80016518       .text update__19mDoExt_3DlineMat1_cFUsR8_GXColorP12dKy_tevstr_c */
void mDoExt_3DlineMat1_c::update(u16, _GXColor&, dKy_tevstr_c*) {
    /* Nonmatching */
    u8* size_p = mpLines->mpSize;
    JUT_ASSERT(5243, size_p != 0);
}

// /* 80016518-8001657C       .text setMat__26mDoExt_3DlineMatSortPacketFP18mDoExt_3DlineMat_c */
// void mDoExt_3DlineMatSortPacket::setMat(mDoExt_3DlineMat_c*) {
//     /* Nonmatching */
// }

/* 8001657C-800165E4       .text draw__26mDoExt_3DlineMatSortPacketFv */
void mDoExt_3DlineMatSortPacket::draw() {
    /* Nonmatching */
}

/* 800165E4-8001683C       .text mDoExt_initFontCommon__FPP7JUTFontPP7ResFONTP7JKRHeapPCcP10JKRArchiveUcUlUl */
void mDoExt_initFontCommon(JUTFont** p_font, ResFONT** p_resfont, JKRHeap* p_heap, const char* param_4,
                           JKRArchive* p_archive, u8 param_6, u32 param_7, u32 param_8) {
    JUTFont* mDoExt_font = *p_font;
    JUT_ASSERT(6648, mDoExt_font == 0);
    ResFONT* mDoExt_resfont = *p_resfont;
    JUT_ASSERT(6649, mDoExt_resfont == 0);
    
    *p_resfont = (ResFONT*)p_archive->getGlbResource('ROOT', param_4, p_archive);
    mDoExt_resfont = *p_resfont;
    JUT_ASSERT(6651, mDoExt_resfont != 0);
    
    if (param_6 == 0) {
        u32 temp = (((param_8+0x1F) & ~0x1F) + 0x40) * param_7;
        JUTCacheFont* cacheFont = new(p_heap, 0) JUTCacheFont(*p_resfont, temp, p_heap);
        if (cacheFont->isValid()) {
            *p_font = cacheFont;
        }
        JKRFileLoader::removeResource(*p_resfont, NULL);
        *p_resfont = NULL;
    } else {
        JUTResFont* resFont = new JUTResFont(*p_resfont, p_heap);
        *p_font = resFont;
    }
    
    if (*p_font && !(*p_font)->isValid()) {
        // "\nFailed to create cache font class\n"
        OSReport_FatalError("\nキャッシュフォントクラス作成に失敗しました\n");
        delete *p_font;
        *p_font = NULL;
    }
    
    mDoExt_font = *p_font;
    JUT_ASSERT(6685, mDoExt_font != 0);
}

JUTFont* mDoExt_font0;
ResFONT* mDoExt_resfont0;
s32 mDoExt_font0_getCount;

/* 80016884-800168E0       .text mDoExt_initFont0__Fv */
void mDoExt_initFont0() {
    static const char fontdata[] = "rock_24_20_4i_usa.bfn";
    mDoExt_initFontCommon(&mDoExt_font0, &mDoExt_resfont0, mDoExt_getZeldaHeap(), fontdata, dComIfGp_getFontArchive(), 1, 0, 0);
}

/* 800168E0-8001691C       .text mDoExt_getMesgFont__Fv */
JUTFont* mDoExt_getMesgFont() {
    if (!mDoExt_font0) {
        mDoExt_initFont0();
    }
    mDoExt_font0_getCount++;
    return mDoExt_font0;
}

/* 8001691C-80016A1C       .text mDoExt_removeMesgFont__Fv */
void mDoExt_removeMesgFont() {
    JUT_ASSERT(6736, mDoExt_font0_getCount > 0);
    
    if (mDoExt_font0_getCount > 0) {
        mDoExt_font0_getCount--;
        JUT_ASSERT(6739, mDoExt_font0_getCount > 0);
        
        if (mDoExt_font0_getCount == 0) {
            delete mDoExt_font0;
            mDoExt_font0 = NULL;
            
            if (mDoExt_resfont0) {
                JKRHeap::free(mDoExt_resfont0, NULL);
                mDoExt_resfont0 = NULL;
            }
        }
    }
}

JUTFont* mDoExt_font1;
ResFONT* mDoExt_resfont1;
s32 mDoExt_font1_getCount;

/* 80016A1C-80016A7C       .text mDoExt_initFont1__Fv */
void mDoExt_initFont1() {
    static const char fontdata[] = "hyrule.bfn";
    mDoExt_initFontCommon(&mDoExt_font1, &mDoExt_resfont1, mDoExt_getZeldaHeap(), fontdata, dComIfGp_getRubyArchive(), 1, 1, 0x8000);
}

/* 80016A7C-80016AB8       .text mDoExt_getRubyFont__Fv */
JUTFont* mDoExt_getRubyFont() {
    if (!mDoExt_font1) {
        mDoExt_initFont1();
    }
    mDoExt_font1_getCount++;
    return mDoExt_font1;
}

/* 80016AB8-80016BB8       .text mDoExt_removeRubyFont__Fv */
void mDoExt_removeRubyFont() {
    JUT_ASSERT(6790, mDoExt_font1_getCount > 0);
    
    if (mDoExt_font1_getCount > 0) {
        mDoExt_font1_getCount--;
        JUT_ASSERT(6793, mDoExt_font1_getCount > 0);
        
        if (mDoExt_font1_getCount == 0) {
            delete mDoExt_font1;
            mDoExt_font1 = NULL;
            
            if (mDoExt_resfont1) {
                JKRHeap::free(mDoExt_resfont1, NULL);
                mDoExt_resfont1 = NULL;
            }
        }
    }
}

/* 80016BB8-80016C98       .text mDoExt_J3DModel__create__FP12J3DModelDataUlUl */
J3DModel* mDoExt_J3DModel__create(J3DModelData* i_modelData, u32 i_modelFlag, u32 i_differedDlistFlag) {
    J3DModel* model = new J3DModel();
    if (model) {
        if (i_modelData->getModelDataType() == 1 && i_modelFlag == 0) {
            if (i_modelFlag = i_modelData->isLocked()) {
                i_modelFlag = 0x20000;
            } else {
                i_modelFlag = 0x80000;
            }
        }
        
        int ret = model->entryModelData(i_modelData, i_modelFlag, 1);
        if (ret == kJ3DError_Success) {
            if (i_modelFlag == 0x80000) {
                if (i_differedDlistFlag & 0x2) {
                    i_differedDlistFlag |= 0x20;
                }
                
                ret = model->newDifferedDisplayList(i_differedDlistFlag);
                if (ret != kJ3DError_Success) {
                    return NULL;
                }
            }
            
            return model;
        }
    }
    return NULL;
}

/* 80016C98-80016CC4       .text setGX__7JUTFontFQ28JUtility6TColorQ28JUtility6TColor */
void JUTFont::setGX(JUtility::TColor, JUtility::TColor) {
    /* Nonmatching */
}

/* 80016CC4-80016CF0       .text getCellWidth__7JUTFontCFv */
int JUTFont::getCellWidth() const {
    /* Nonmatching */
}

/* 80016CF0-80016D1C       .text getCellHeight__7JUTFontCFv */
s32 JUTFont::getCellHeight() const {
    /* Nonmatching */
}

/* 80016D1C-80016D78       .text __dt__26mDoExt_3DlineMatSortPacketFv */
mDoExt_3DlineMatSortPacket::~mDoExt_3DlineMatSortPacket() {
    /* Nonmatching */
}

/* 80016D78-80016D80       .text getMaterialID__19mDoExt_3DlineMat1_cFv */
int mDoExt_3DlineMat1_c::getMaterialID() {
    return 1;
}

/* 80016D80-80016D88       .text getMaterialID__19mDoExt_3DlineMat0_cFv */
int mDoExt_3DlineMat0_c::getMaterialID() {
    return 0;
}

/* 80016D88-80016DE4       .text __dt__24mDoExt_onCupOffAupPacketFv */
mDoExt_onCupOffAupPacket::~mDoExt_onCupOffAupPacket() {
    /* Nonmatching */
}

/* 80016DE4-80016E40       .text __dt__24mDoExt_offCupOnAupPacketFv */
mDoExt_offCupOnAupPacket::~mDoExt_offCupOnAupPacket() {
    /* Nonmatching */
}

/* 80016E40-80016F14       .text __dt__15mDoExt_McaMorf2Fv */
mDoExt_McaMorf2::~mDoExt_McaMorf2() {
    /* Nonmatching */
}

/* 80017000-800170D4       .text __dt__14mDoExt_McaMorfFv */
mDoExt_McaMorf::~mDoExt_McaMorf() {
    /* Nonmatching */
}

/* 800170D4-800171BC       .text __dt__28mDoExt_MtxCalcAnmBlendTblOldFv */
mDoExt_MtxCalcAnmBlendTblOld::~mDoExt_MtxCalcAnmBlendTblOld() {
    /* Nonmatching */
}
