Skip to content

MISC: Prepare for breaking changes in v3.0.0 - #482

Merged
alainbryden merged 7 commits into
alainbryden:mainfrom
catloversg:pull-request/misc/Prepare-for-breaking-changes-in-v3.0.0
Feb 23, 2026
Merged

alainbryden merged 7 commits into
alainbryden:mainfrom
catloversg:pull-request/misc/Prepare-for-breaking-changes-in-v3.0.0

Conversation

@catloversg

Copy link
Copy Markdown
Contributor

I'm going to finish the planned breaking changes for v3, so the first beta version of v3 is coming soon. It's time to prepare for those changes. For more information, please check bitburner-official/bitburner-src#2148.

This PR helps your scripts to run in both v2.8.1 and v3.0.0.

@alainbryden

alainbryden commented Feb 21, 2026 •

Copy link
Copy Markdown
Owner

As mentioned in Discord last year, thanks for this PR, it's a big leg up. Just leaving some notes for myself here, as I do plan on implementing this a bit differently (although you're welcome to take a stab here if so-inspired):

  1. Rather than adding this new getCompatibleApi call everywhere something has changed, simply use the new function names.
    e.g. Go ahead and change
    await getNsDataThroughFile(ns, 'ns.stock.hasTIXAPIAccess()'); to
    await getNsDataThroughFile(ns, 'ns.stock.hasTixApiAccess()');

  2. To avoid breaking on older (< v3) versions of the game, we can take advantage of the fact that I'm already invoking functions indirectly (via getNsDataThroughFile) and add backwards-compatibility logic there.

    Within the function runCommand_Custom - which is the innermost guts of all ram-dodging / indirect ns function calls, we can simply intercept the command being written to the new temporary script file:

    if (ns.ui.getGameInfo().versionNumber < 44)
        command = command.replaceAll('hasWseAccount', 'hasWSEAccount')
                         .replaceAll('hasTixApiAccess', 'hasTIXAPIAccess')
                         .replaceAll('has4SDataTixApi', 'has4SDataTIXAPI')

    This leaves all call sites looking nearly identical, and not requiring any new imports, but ensures that all temp scripts generated by the ram-dodging infrastructure contain the correct function name for the version of the game that's running.

  3. The above should handle 90% of cases (esp. function renames), and then there's just a one or two other situations (like accessing bitnode mults under a new name) which we can fix with more situational changes. In such cases, I would opt to update tryGetBitNodeMultipliers (and similar usages) with a change like:

    export async function tryGetBitNodeMultipliers_Custom(ns, fnGetNsDataThroughFile) {
        //...
        if (canGetBitNodeMultipliers) {
            try {
                mults = await fnGetNsDataThroughFile(ns, 'ns.getBitNodeMultipliers()', '/Temp/bitNode-multipliers.txt', null, null, null, null, /*silent:*/true);
                // If running an older version of the game, some property names need to be updated.
                mults.FavorToDonateToFaction ??= mults.RepToDonateToFaction;
                return mults;
            } catch { }
           //...

    This sort of approach is simple enough that we don't even have to check the version, so it can happen anywhere a property has been renamed.

@alainbryden alainbryden left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per comments

@catloversg

Copy link
Copy Markdown
Contributor Author

New changes:

Error log:

ERROR: Tasks/backdoor-all-servers.js Caught an unexpected error: Error: ns.read('/Temp/getServerRequiredHackingLevel-all.txt') returned a bad result: "ERROR: RUNTIME ERROR Temp/getServerRequiredHackingLevel-all.txt.js@home (PID - 64487) getServerRequiredHackingLevel: Cannot be executed on hacknet-server-0. The server must not be a hacknet server. Stack: Temp/getServerRequiredHackingLevel-all.txt.js:L-1@unknown Temp/getServerRequiredHackingLevel-all.txt.js:L3@main". Script: /Temp/getServerRequiredHackingLevel-all.txt.js Args: ["home","n00dles","foodnstuff","sigma-cosmetics","joesguns","hong-fang-tea","harakiri-sushi","iron-gym","hacknet-server-0","hacknet-server-1","hacknet-server-2","hacknet-server-3","hacknet-server-4","max-hardware","zer0","nectar-net","CSEC","neo-net","omega-net","silver-helix","phantasy","computek","crush-fitness","the-hub","netlink","johnson-ortho","avmnite-02h","rothman-uni","zb-institute","summit-uni","syscore","catalyst","I.I.I.I","aevum-police","millenium-fitness","lexo-corp","rho-construction","alpha-ent","global-pharm","snap-fitness","galactic-cyber","aerocorp","omnia","deltaone","unitalife","solaris","defcomm","icarus","univ-energy","zeus-med","taiyang-digital","nova-med","infocomm","zb-def","applied-energetics","titan-labs","microdyne","run4theh111z","stormtech","helios","vitalife","fulcrumtech","kuai-gong","4sigma","omnitek",".","blade","b-and-a","nwo","clarkinc","powerhouse-fitness","ecorp","megacorp","The-Cave","fulcrumassets"] Command: Object.fromEntries(ns.args.map(server => [server, ns.getServerRequiredHackingLevel(server)])) The script was likely passed invalid arguments. Please post a screenshot of this error on discord. at asError (home/helpers.js:427:9) at autoRetry (home/helpers.js:465:23) at async getNsDataThroughFile_Custom (home/helpers.js:243:22) at async getNsDataThroughFile (home/helpers.js:159:12) at async main (home/Tasks/backdoor-all-servers.js:37:43) at async startNetscript2Script (webpack://bitburner/./src/NetscriptWorker.ts?:88:3)

@alainbryden alainbryden left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great. Thanks for catching some other typos and bugs on the way.

Comment thread helpers.js Outdated
Comment thread helpers.js Outdated
Comment thread helpers.js Outdated
Comment thread helpers.js
@alainbryden

Copy link
Copy Markdown
Owner

Fix an error caused by the breaking changes in API: Make some APIs throw error when server is invalid bitburner-official/bitburner-src#2261. There may be some other affected code that I don't know. Please double-check.

Off the top of my head, this might also affect run scan.js and stats.js. Happy to test it out and fix if needed once this is merged.

@alainbryden alainbryden left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again

@alainbryden
alainbryden merged commit fae2f96 into alainbryden:main Feb 23, 2026
1 check passed
@alainbryden alainbryden added enhancement New feature or request refactor labels Feb 23, 2026
@catloversg
catloversg deleted the pull-request/misc/Prepare-for-breaking-changes-in-v3.0.0 branch February 23, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants