// DIE's signature file
// Author: LinXP

init("archive", "Unity");

function detect(bShowType, bShowVersion, bShowOptions) {
    var nFileVer, sEngineVer, sMinPlayerVer
    if (Binary.getSize() >= 0x07) {
        if (Binary.compare("'UnityFS'00")) {
            sName += "/UnityFS";
            nFileVer = Binary.read_uint32(0x8, _BE);
            sEngineVer = Binary.getString(0x12);
            sMinPlayerVer = Binary.getString(0x0C);
            if (sEngineVer && sMinPlayerVer) {
                sVersion = sVersion.append("FileVer:" + nFileVer);
                sVersion = sVersion.append("EngineVer:" + sEngineVer);
                sVersion = sVersion.append("MinPlayerVer:" + sMinPlayerVer);
                bDetected = true;
            }
        } else if (Binary.compare("'UnityRaw'00")) {
            sName += "/UnityRaw";
            nFileVer = Binary.read_uint32(0x9, _BE);
            sEngineVer = Binary.getString(0x13);
            sMinPlayerVer = Binary.getString(0x0D);
            if (sEngineVer && sMinPlayerVer) {
                sVersion = sVersion.append("FileVer:" + nFileVer);
                sVersion = sVersion.append("EngineVer:" + sEngineVer);
                sVersion = sVersion.append("MinPlayerVer:" + sMinPlayerVer);
                bDetected = true;
            }
        } else if (Binary.compare("'UnityWeb'00")) {
            sName += "/UnityWeb";
            nFileVer = Binary.read_uint32(0x9, _BE);
            sEngineVer = Binary.getString(0x13);
            sMinPlayerVer = Binary.getString(0x0D);
            if (sEngineVer && sMinPlayerVer) {
                sVersion = sVersion.append("FileVer:" + nFileVer);
                sVersion = sVersion.append("EngineVer:" + sEngineVer);
                sVersion = sVersion.append("MinPlayerVer:" + sMinPlayerVer);
                bDetected = true;
            }
        } else if (Binary.read_uint32(0x10, _BE) == 0) {
            sName += "/Unity Asset";
            nFileVer = Binary.read_uint32(0x8, _BE);
            switch (nFileVer) {
                case 9:
                    sEngineVer = Binary.getString(0x14);
                    break;
                case 15:
                    sEngineVer = Binary.getString(0x14);
                    break;
                case 17:
                    sEngineVer = Binary.getString(0x14);
                    break;
                case 20:
                    sEngineVer = Binary.getString(0x14);
                    break;
                case 21:
                    sEngineVer = Binary.getString(0x14);
                    break;
                case 22:
                    sEngineVer = Binary.getString(0x30);
                    break;
            }
            if (sEngineVer && nFileVer <= 22 && nFileVer >= 8) {
                sVersion = sVersion.append("FileVer:" + nFileVer);
                sVersion = sVersion.append("EngineVer:" + sEngineVer);
                bDetected = true;
            }
        }
    }
    return result(bShowType, bShowVersion, bShowOptions);
}