diff --git a/markdown/bitburner.singularity.getsavedata.md b/markdown/bitburner.singularity.getsavedata.md new file mode 100644 index 000000000..e48925b28 --- /dev/null +++ b/markdown/bitburner.singularity.getsavedata.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [Singularity](./bitburner.singularity.md) > [getSaveData](./bitburner.singularity.getsavedata.md) + +## Singularity.getSaveData() method + +This function returns the save data. + +**Signature:** + +```typescript +getSaveData(): Promise; +``` +**Returns:** + +Promise<Uint8Array> + +## Remarks + +RAM cost: 1 GB \* 16/4/1 + diff --git a/markdown/bitburner.singularity.md b/markdown/bitburner.singularity.md index 012af34d5..ad4965ebc 100644 --- a/markdown/bitburner.singularity.md +++ b/markdown/bitburner.singularity.md @@ -56,6 +56,7 @@ This API requires Source-File 4 to use. The RAM cost of all these functions is m | [getFactionWorkTypes(faction)](./bitburner.singularity.getfactionworktypes.md) | Get the work types of a faction. | | [getOwnedAugmentations(purchased)](./bitburner.singularity.getownedaugmentations.md) | Get a list of owned augmentation. | | [getOwnedSourceFiles()](./bitburner.singularity.getownedsourcefiles.md) | Get a list of acquired Source-Files. | +| [getSaveData()](./bitburner.singularity.getsavedata.md) | This function returns the save data. | | [getUpgradeHomeCoresCost()](./bitburner.singularity.getupgradehomecorescost.md) | Get the price of upgrading home cores. | | [getUpgradeHomeRamCost()](./bitburner.singularity.getupgradehomeramcost.md) | Get the price of upgrading home RAM. | | [goToLocation(locationName)](./bitburner.singularity.gotolocation.md) | Go to a location. | diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 2f8cb5618..7d61faefc 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -215,6 +215,7 @@ const singularity = { installAugmentations: SF4Cost(RamCostConstants.SingularityFn3), isFocused: SF4Cost(0.1), setFocus: SF4Cost(0.1), + getSaveData: SF4Cost(RamCostConstants.SingularityFn1 / 2), exportGame: SF4Cost(RamCostConstants.SingularityFn1 / 2), exportGameBonus: SF4Cost(RamCostConstants.SingularityFn1 / 4), b1tflum3: SF4Cost(16), diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index 276606993..98737302d 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -1169,6 +1169,17 @@ export function NetscriptSingularity(): InternalAPI { if (!Player.currentWork) return null; return Player.currentWork.APICopy(); }, + getSaveData: (ctx) => async () => { + helpers.checkSingularityAccess(ctx); + const saveData = await saveObject.getSaveData(); + if (typeof saveData === "string") { + // saveData is the base64-encoded json save string. A base64-encoded string only uses ASCII characters, so it's + // fine to use new TextEncoder().encode() to encode it to a Uint8Array. + return new TextEncoder().encode(saveData); + } + // saveData is the compressed json save string. + return saveData; + }, exportGame: (ctx) => () => { helpers.checkSingularityAccess(ctx); onExport(); diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 3814a62f4..ea35dd170 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -1793,6 +1793,14 @@ export interface BitNodeBooleanOptions { * @public */ export interface Singularity { + /** + * This function returns the save data. + * + * @remarks + * RAM cost: 1 GB * 16/4/1 + */ + getSaveData(): Promise; + /** * Backup game save. * @remarks