// Author: DosX
// E-Mail: collab@kay-software.ru
// GitHub: https://github.com/DosX-dev
// Telegram: @DosX_dev

init("library", "Direct3D");

function detect(bShowType, bShowVersion, bShowOptions) {
    if (PE.isLibraryPresentExp(/^d3d*/i)) {
        bDetected = true;

        var runtimeLibrary = PE.isLibraryPresentExp(/^d3d\d/i);

        // d3d12.dll -> d3d[12].dll -> Direct3D v12
        if (runtimeLibrary != null) {

            var versionNumber = String(runtimeLibrary).substr(3, 2);

            if (isNumber(versionNumber)) { // 10+
                sVersion = versionNumber;
            } else { // 8, 9
                sVersion = versionNumber[0];
            }
        }

    }

    return result(bShowType, bShowVersion, bShowOptions);
}

// Checks whether the resulting string is a number
function isNumber(str) {
    if (str.length === 0) return false;
    for (var n = 0; n < str.length; n++)
        for (var e = 0; e < 10 && str[n] !== "0123456789" [e]; e++)
            if (e === 9) return false;
    return true;
}