镜像:KintaroModding/phantombladezero_simplepower(2026-11-30,快照)
This commit is contained in:
commit
f4e80dd132
14 files changed
+1291
No files matched your search
@@ -0,0 +1,9 @@
|
||||
* text=auto eol=lf
|
||||
*.uasset binary
|
||||
*.uexp binary
|
||||
*.pak binary
|
||||
*.utoc binary
|
||||
*.ucas binary
|
||||
*.locres binary
|
||||
# Settings files that players edit by hand: Windows line ends (PBZModLoader mods: in the mod folder)
|
||||
src/*/*.txt text eol=crlf
|
||||
@@ -0,0 +1,2 @@
|
||||
dist/
|
||||
__pycache__/
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Kintaro
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,88 @@
|
||||
# Simple Power
|
||||
|
||||
The player's hits deal more health damage and more Sha-Chi damage, the player's parries more Sha-Chi damage: one multiplier for each, x1.5 by default, 0.1 to 10. Enemies are not changed. A PBZModLoader mod; settings in a text file in its folder, or on its Mods Menu page.
|
||||
|
||||
A [PBZModLoader](https://github.com/KintaroModding/phantombladezero_pbzmodloader) mod for Phantom Blade Zero (Unreal Engine
|
||||
5.7), made with game version `CL-302256_JKS-17280` and PBZModLoader 2.1.0. This README is for developers.
|
||||
What the mod does, how to install it and its compatibility are in [openmods.md](openmods.md), the mod page on
|
||||
[openmods](https://openmods.nexus).
|
||||
|
||||
## How it works
|
||||
|
||||
The game runs much of its logic in JavaScript (Puerts). PBZModLoader loads every folder in
|
||||
`ProjectPBZ/PBZModLoader/mods/` that has a `main.js`, through the game's own module system, after the game's
|
||||
`MainStart`; `require("ue")`, `require("puerts")` and `require("Library/TsHelper")` are the game's modules, and
|
||||
`puerts.argv.getByName("GameInstance")` gives the game instance. Before a reload (Alt+F5) the loader awaits the mod's
|
||||
`stop()`, which must give back everything the mod changed.
|
||||
|
||||
`src/phantombladezero_simplepower/main.js` raises three attributes of the player character (`UBasicAttributeSet`):
|
||||
`Attack` (health damage), `ShachiAttack` (the Sha-Chi damage of hits) and `Amplification_ReflectShachi` (the Sha-Chi
|
||||
damage of parries, a share on top: 0.5 = 50% more). Every 500 ms it looks at
|
||||
`GameplayStatics.GetPlayerCharacter` and its ability system:
|
||||
|
||||
- **The effects:** the game has a ready-made gameplay effect per attribute and operation,
|
||||
`/PBZCombatAsset/Config/AttributesModifyEffect/GE_MA_<attribute>_<0|1>_<operation>` (0 = `HasDuration`, 1 = instant).
|
||||
The mod uses `GE_MA_Attack_0_Mul`, `GE_MA_ShachiAttack_0_Mul` (one modifier, `Multiplicitive`) and
|
||||
`GE_MA_Amplification_ReflectShachi_0_Add` (one modifier, `Additive`, the multiplier minus 1): `HasDuration`,
|
||||
SetByCaller magnitude `AttributeOpMagnitude`. It builds the spec (`MakeSpecHandle`, `AssignSetByCallerMagnitude`,
|
||||
`SetDuration` 1,000,000 s) and applies it with `BP_ApplyGameplayEffectSpecToSelf`, as Faster Movement does for the
|
||||
speeds. `AttributeUtils.AddAttributeBuff` is not used: it ran as an instant effect in game.
|
||||
- **Parries:** the game takes a share of the enemy's Sha-Chi bar there (a perfect parry twice an imperfect one, after
|
||||
which the player loses Sha-Chi too), and `ShachiAttack` does not count: measured at x1.5 and x10, the same parry took
|
||||
the same amount. A held block took nothing from the enemy. The game's own Sha-Chi
|
||||
accessory (`GE_Accessory_ShachiAttack_Lv1`, `_Lv2`) adds to `Amplification_ReflectShachi`, so the mod does the same.
|
||||
- **Only the current value:** a timed effect leaves the base value alone, so nothing of it reaches the save. Should an
|
||||
effect ever land on the base value, the mod puts the base back, warns and ends for the session.
|
||||
- **One effect per attribute:** the handles are kept per character path name. An effect that is no longer active (death,
|
||||
load) is put on again; a changed multiplier takes the old effect off first; a multiplier of 1 has no effect at all. An
|
||||
effect that cannot be taken off blocks the new one, so the multipliers never stack.
|
||||
- **Give back:** `Enable=Off` and `stop()` take all effects off. A poll that throws is tried again; 10 in a row (a
|
||||
class or asset is gone after a game update) end the mod for the session with one warning.
|
||||
- **Stacking with other effects:** the engine adds up multipliers of the same operation on one attribute (x1.5 and x1.3
|
||||
give x1.8); a changed base value (a level, Phantom Tuner) multiplies.
|
||||
|
||||
- **Settings file:** `phantombladezero_simplepower.txt` next to `main.js` (`__dirname`, the mod's folder as a full path), read every
|
||||
2 s with `EasyCsv.LoadStringFromLocalFile` and written with the defaults when missing. The shipped file is exactly the
|
||||
script's default text (`tests/test_mod.js` checks it).
|
||||
- **Mods Menu, optional:** PBZModLoader starts its mods after Mods Menu's, so a running Mods Menu (0.9.0 or later) has
|
||||
its registry object in `globalThis.PBZModsMenu` by then. Only when it has the features `settingsPath` and
|
||||
`store.saved`, the mod pushes its page (id `phantombladezero_simplepower`, `store: "saved"`) and reads the file the page saves
|
||||
(`PBZModsMenu.settingsPath(id)`, in Mods Menu's Saved folder): a registered page cannot save anywhere else.
|
||||
- **Log:** a line per effect with the value before and after (`Attack x1.5: Attack 100 -> 150`), at most 30 per start.
|
||||
`console.log` lines that start with `[PBZMOD]` and the game's warnings reach `ProjectPBZ/PBZModLoader/loader.log`.
|
||||
|
||||
## Check and deploy
|
||||
|
||||
Requirements: Windows PowerShell 5.1 and [Node.js](https://nodejs.org/) (for `node --check` and the offline test).
|
||||
|
||||
```powershell
|
||||
powershell -ExecutionPolicy Bypass -File .\build.ps1 # node --check, tests\test_mod.js
|
||||
powershell -ExecutionPolicy Bypass -File .\build.ps1 -Deploy # the checks, then deploy.ps1
|
||||
powershell -ExecutionPolicy Bypass -File .\deploy.ps1 # copy src\phantombladezero_simplepower to the game
|
||||
```
|
||||
|
||||
`deploy.ps1` mirrors `src\phantombladezero_simplepower\` to `<game folder>\ProjectPBZ\PBZModLoader\mods\phantombladezero_simplepower\`. The
|
||||
settings file that is already there is the tester's and stays; `-ResetConfig` copies the shipped one. The game folder
|
||||
comes from `gameDir` in `_tools\gamedata\phantombladezero\game.json`, else `$env:UE5_GAMES_DIR\PBZ`; `-GameDir` or
|
||||
`-ModsDir` override it. It stops when PBZModLoader is not installed (its start file
|
||||
`ProjectPBZ\Content\JavaScript\PBZModLoader\bootstrap.js` is missing).
|
||||
|
||||
The GitHub release zip holds the mod folder at `ProjectPBZ/PBZModLoader/mods/phantombladezero_simplepower/`, so players unpack it
|
||||
into the game folder.
|
||||
|
||||
Versioning: every change raises the second number in `mod.json` and `main.js` (1.0 -> 1.1): `python scripts\bump_version.py`.
|
||||
|
||||
## Project layout
|
||||
|
||||
```
|
||||
src/phantombladezero_simplepower/ The mod folder: main.js and the shipped settings file
|
||||
tests/test_mod.js Offline test of main.js (Node.js, stand-ins for the game)
|
||||
docs/ Cover and screenshots
|
||||
scripts/ bump_version.py, check_openmods.py, publish.ps1
|
||||
build.ps1, deploy.ps1 Checks; copy into the game
|
||||
mod.json Name, version, game, kind pbzmodloader, modsPath
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT, see [LICENSE](LICENSE).
|
||||
@@ -0,0 +1,50 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Checks the PBZModLoader mod: node --check of every .js in src, then tests\test_mod.js; -Deploy then runs deploy.ps1.
|
||||
|
||||
.DESCRIPTION
|
||||
A PBZModLoader mod needs no build: src\<folder> is the mod folder as it goes into the game. This script checks it
|
||||
with Node.js (https://nodejs.org/), which must be on the PATH. The GitHub release zip is made by the playbook's
|
||||
publish tool from src\<folder> (kind pbzmodloader in mod.json).
|
||||
|
||||
Exit codes: 0 = all checks passed (and deployed with -Deploy), 1 = a check failed or an error.
|
||||
|
||||
.EXAMPLE
|
||||
powershell -ExecutionPolicy Bypass -File .\build.ps1 -Deploy
|
||||
#>
|
||||
param(
|
||||
# After the checks, copy the mod into the game (deploy.ps1).
|
||||
[switch]$Deploy,
|
||||
# Passed on to deploy.ps1: copy the shipped settings file over the one in the game.
|
||||
[switch]$ResetConfig
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
|
||||
throw "Node.js (node) is not on the PATH."
|
||||
}
|
||||
$mod = Get-Content (Join-Path $PSScriptRoot "mod.json") -Raw | ConvertFrom-Json
|
||||
$source = Join-Path $PSScriptRoot "src\$($mod.folder)"
|
||||
foreach ($file in Get-ChildItem $source -Recurse -Filter *.js) {
|
||||
node --check $file.FullName
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "Syntax error in $($file.FullName)" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
node (Join-Path $PSScriptRoot "tests\test_mod.js")
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "tests\test_mod.js failed." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
Write-Host "$($mod.name) $($mod.version): all checks passed." -ForegroundColor Green
|
||||
if ($Deploy) {
|
||||
$arguments = @{}
|
||||
if ($ResetConfig) {
|
||||
$arguments.ResetConfig = $true
|
||||
}
|
||||
& (Join-Path $PSScriptRoot "deploy.ps1") @arguments
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
exit 0
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Copies the PBZModLoader mod (src\<folder>) into the game's ProjectPBZ\PBZModLoader\mods\<folder>.
|
||||
|
||||
.DESCRIPTION
|
||||
Reads mod.json. The target is <game folder>\<modsPath>\<folder>; the game folder is gameDir of
|
||||
_tools\gamedata\<game>\game.json, else $env:UE5_GAMES_DIR\<gameFolder>, unless -GameDir or -ModsDir is given.
|
||||
PBZModLoader must be installed in the game (its start file ProjectPBZ\Content\JavaScript\PBZModLoader\bootstrap.js).
|
||||
|
||||
The script mirrors src\<folder> into the target: files that are no longer in src are removed there, and nothing
|
||||
else in the mods folder is touched. PBZModLoader loads its mods at game start (Alt+F5 reloads them while the game
|
||||
runs).
|
||||
|
||||
An existing settings file (<folder>.txt) in the game stays: it holds the settings of the one who tests, and the
|
||||
mod takes the default for every setting it lacks. -ResetConfig copies the shipped one over it.
|
||||
|
||||
Exit codes: 0 = deployed or already up to date, 1 = error.
|
||||
|
||||
.EXAMPLE
|
||||
powershell -ExecutionPolicy Bypass -File .\deploy.ps1
|
||||
#>
|
||||
param(
|
||||
# The game's install folder. Default: gameDir of _tools\gamedata\<game>\game.json, else $env:UE5_GAMES_DIR\<gameFolder of mod.json>.
|
||||
[string]$GameDir,
|
||||
# PBZModLoader's mods folder. Default: <GameDir>\<modsPath of mod.json>.
|
||||
[string]$ModsDir,
|
||||
# Copy the shipped settings file over the one in the game.
|
||||
[switch]$ResetConfig
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# The game folder: "gameDir" of _tools\gamedata\<game>\game.json, for a game outside UE5_GAMES_DIR (for example in a
|
||||
# Steam library), else $env:UE5_GAMES_DIR\<gameFolder of mod.json>; $null when neither is known. The tools folder is
|
||||
# $env:UE5_TOOLS, else the first _tools folder above the project (a plain clone has none).
|
||||
function Get-GameDir {
|
||||
$toolsDir = $env:UE5_TOOLS
|
||||
if (-not $toolsDir -and $PSScriptRoot) {
|
||||
$dir = Split-Path $PSScriptRoot -Parent
|
||||
while (-not $toolsDir -and $dir) {
|
||||
if (Test-Path (Join-Path $dir "_tools")) {
|
||||
$toolsDir = Join-Path $dir "_tools"
|
||||
}
|
||||
$dir = Split-Path $dir -Parent
|
||||
}
|
||||
}
|
||||
if ($toolsDir) {
|
||||
$gameJson = Join-Path $toolsDir "gamedata\$($mod.game)\game.json"
|
||||
if (Test-Path $gameJson) {
|
||||
$gameInfo = Get-Content $gameJson -Raw | ConvertFrom-Json
|
||||
if ($gameInfo.gameDir) {
|
||||
return $gameInfo.gameDir
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($env:UE5_GAMES_DIR) {
|
||||
return Join-Path $env:UE5_GAMES_DIR $mod.gameFolder
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
$mod = Get-Content (Join-Path $PSScriptRoot "mod.json") -Raw | ConvertFrom-Json
|
||||
$source = Join-Path $PSScriptRoot "src\$($mod.folder)"
|
||||
if (-not (Test-Path (Join-Path $source "main.js"))) {
|
||||
throw "$source\main.js not found."
|
||||
}
|
||||
if (-not $ModsDir) {
|
||||
if (-not $GameDir) {
|
||||
$GameDir = Get-GameDir
|
||||
}
|
||||
if (-not $GameDir) {
|
||||
throw "The game folder is unknown: set UE5_GAMES_DIR (the folder that holds '$($mod.gameFolder)'), give the game a gameDir in _tools\gamedata\$($mod.game)\game.json, or use -GameDir or -ModsDir."
|
||||
}
|
||||
$startFile = Join-Path $GameDir "ProjectPBZ\Content\JavaScript\PBZModLoader\bootstrap.js"
|
||||
if (-not (Test-Path $startFile)) {
|
||||
throw "PBZModLoader is not installed in the game ($startFile is missing). Install PBZModLoader first."
|
||||
}
|
||||
$ModsDir = Join-Path $GameDir $mod.modsPath
|
||||
}
|
||||
$target = Join-Path $ModsDir $mod.folder
|
||||
|
||||
# robocopy neither copies nor removes an excluded file, so /XF keeps the game's settings file.
|
||||
$settings = "$($mod.folder).txt"
|
||||
$keepSettings = (-not $ResetConfig) -and (Test-Path (Join-Path $target $settings))
|
||||
$options = @("/MIR", "/NFL", "/NDL", "/NJH", "/NJS", "/NP")
|
||||
if ($keepSettings) {
|
||||
$options += @("/XF", $settings)
|
||||
}
|
||||
robocopy $source $target @options | Out-Null
|
||||
$code = $LASTEXITCODE
|
||||
if ($code -ge 8) {
|
||||
throw "robocopy failed with exit code $code"
|
||||
}
|
||||
if ($code -eq 0) {
|
||||
Write-Host "Already up to date: $target" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "Deployed $($mod.name) $($mod.version) to $target (active from the next game start, or Alt+F5)" -ForegroundColor Green
|
||||
}
|
||||
if ($keepSettings) {
|
||||
Write-Host "Kept the game's $settings; -ResetConfig copies the shipped one."
|
||||
}
|
||||
exit 0
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 207 KiB |
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "Simple Power",
|
||||
"folder": "phantombladezero_simplepower",
|
||||
"author": "Kintaro",
|
||||
"version": "1.2",
|
||||
"description": "The player's hits deal more health damage and more Sha-Chi damage, the player's parries more Sha-Chi damage: one multiplier for each, x1.5 by default, 0.1 to 10. Enemies are not changed. A PBZModLoader mod; settings in a text file in its folder, or on its Mods Menu page.",
|
||||
"kind": "pbzmodloader",
|
||||
"game": "phantombladezero",
|
||||
"gameFolder": "PBZ",
|
||||
"modsPath": "ProjectPBZ\\PBZModLoader\\mods",
|
||||
"gameVersion": "CL-302256_JKS-17280",
|
||||
"engine": "UE5_7",
|
||||
"pbzmodloader": "2.1.0"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"$schema": "https://openmods.nexus/openmods.schema.json",
|
||||
"openmods": 1,
|
||||
"name": "Simple Power",
|
||||
"summary": "Your hits deal more health and Sha-Chi damage, your parries more Sha-Chi damage: one multiplier each, only for you. A PBZModLoader mod, live settings.",
|
||||
"games": ["phantom-blade-zero"],
|
||||
"tags": ["gameplay"],
|
||||
"requires": ["PBZModLoader (tested with 2.1.0)"],
|
||||
"gameVersions": ["Steam build 26367565"],
|
||||
"cover": "docs/cover.webp"
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
# Simple Power
|
||||
|
||||
Your hits deal more health and Sha-Chi damage, your parries more Sha-Chi damage: one multiplier each, only for you. A PBZModLoader mod, live settings.
|
||||
|
||||
## What it does
|
||||
|
||||
Your attacks and parries are stronger. Three multipliers, each from 0.1 to 10, set live:
|
||||
|
||||
- **Attack:** the health damage you deal (x1.5 as installed).
|
||||
- **Sha-Chi Attack:** the Sha-Chi damage your hits deal, so enemies break sooner (x1.5 as installed).
|
||||
- **Parry Sha-Chi:** the Sha-Chi damage your parries deal (x1.5 as installed). A held block deals none, so nothing
|
||||
changes there.
|
||||
|
||||
Only your character gets stronger. Enemies are not changed: their health, their Sha-Chi and their damage stay the
|
||||
game's own.
|
||||
|
||||
It is a PBZModLoader mod: a script in the game's own script engine. It replaces no game file and writes nothing into
|
||||
the save: it puts three of the game's own timed effects on your character, on top of your stock values, so with the mod
|
||||
removed you are back to stock.
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||
|
||||
## How to install
|
||||
|
||||
1. Install [PBZModLoader](https://github.com/KintaroModding/phantombladezero_pbzmodloader) 2.1.0 or later.
|
||||
2. Download the zip of the latest release on GitHub (`phantombladezero_simplepower_<version>.zip`).
|
||||
3. Unpack it into the game folder (the folder that holds `ProjectPBZ`). It adds the folder
|
||||
`ProjectPBZ\PBZModLoader\mods\phantombladezero_simplepower\` with `main.js` and the settings file.
|
||||
4. Start the game.
|
||||
|
||||
To check that it runs: `ProjectPBZ\PBZModLoader\loader.log` has the line
|
||||
`[PBZMOD] [Simple Power] <version> started; settings: ...`.
|
||||
|
||||
To update the mod, replace `main.js` with the one of the new release; keep your settings file (a setting that it does
|
||||
not have keeps its default). To remove the mod, delete the folder `ProjectPBZ\PBZModLoader\mods\phantombladezero_simplepower\`.
|
||||
|
||||
## How to use
|
||||
|
||||
Nothing to do: the mod works as soon as you load a game (x1.5 for all three).
|
||||
|
||||
To change the values, use the Mods Menu page or the settings file below. A change counts within a few seconds, without
|
||||
a restart and without loading the save again.
|
||||
|
||||
## Settings
|
||||
|
||||
The settings are in `ProjectPBZ\PBZModLoader\mods\phantombladezero_simplepower\phantombladezero_simplepower.txt`. Open it with a text editor,
|
||||
change a value and save: the mod reads the file every 2 seconds, so the game uses it without a restart. Without the
|
||||
file the mod writes it with the defaults below. Keys are not case-sensitive; `;` or `#` starts a comment.
|
||||
|
||||
**With Mods Menu** (0.9.0 or later) in the game, the mod adds its page to Mods Menu's tab in the game's settings, and
|
||||
the page's settings are the ones that count: Mods Menu keeps them in its own file in the game's `Saved` folder, and
|
||||
the file in the mod's folder is not read then.
|
||||
|
||||
| Setting | Default | What it does |
|
||||
|---|---|---|
|
||||
| `Enable` | `On` | `Off`: the mod does nothing, the game's values come back |
|
||||
| `Attack` | `1.5` | The health damage you deal, 0.1 to 10 (1 = the game's own, 1.5 = 50% more, 2 = double) |
|
||||
| `ShaChiAttack` | `1.5` | The Sha-Chi damage your hits deal, 0.1 to 10 (1 = the game's own, 1.5 = 50% more, 2 = double) |
|
||||
| `ParryShaChi` | `1.5` | The Sha-Chi damage your parries deal, 0.1 to 10 (1 = the game's own, 1.5 = 50% more, 2 = double) |
|
||||
|
||||
## Compatibility
|
||||
|
||||
- Game version: Steam build 26367565 (`CL-302256_JKS-17280`).
|
||||
- Needs PBZModLoader 2.1.0 or later. Mods Menu is optional.
|
||||
- [Phantom Tuner](https://github.com/KintaroModding/phantombladezero_phantomtuner) has its own `PlayerAttack` and
|
||||
`PlayerShaChiAttack`. Both can run together: the values then multiply (x1.5 here and x2 there give x3). Nothing loops
|
||||
or grows by itself. Use the one you prefer, or set the other to 1.
|
||||
- [Heaven or Hell](https://github.com/KintaroModding/phantombladezero_heavenorhell) writes your attack directly while
|
||||
it runs, so `Attack` here does not show next to it. Set `Attack=1` and use only `ShaChiAttack`.
|
||||
- Another mod that changes the player's attack or Sha-Chi attack: test them together.
|
||||
|
||||
## Known issues
|
||||
|
||||
- None known.
|
||||
|
||||
## How to build
|
||||
|
||||
There is nothing to build: `src\phantombladezero_simplepower\` is the mod folder (`main.js` and the settings file).
|
||||
`tests\test_mod.js` runs the script outside the game with Node.js and stand-ins for the game: `node tests\test_mod.js`.
|
||||
`README.md` has the details.
|
||||
|
||||
## Credits
|
||||
|
||||
Made by Kintaro. MIT license: you may use, change and share this mod. PBZModLoader is made by LKF, its fork by
|
||||
KintaroModding. Phantom Blade Zero and its files belong to their makers.
|
||||
@@ -0,0 +1,67 @@
|
||||
"""Raises the version of the mod by one step: the second number (1.0 -> 1.1, 1.9 -> 1.10).
|
||||
|
||||
The version is in mod.json ("version": "<major>.<minor>"). Some mods also write it into their log line, so the script
|
||||
also changes that line when its file exists: `local VERSION = "<major>.<minor>"` in src/<folder>/Scripts/main.lua (UE4SS
|
||||
mods), and the first `const <NAME>_VERSION = "<major>.<minor>";` in src/<folder>/main.js (PBZModLoader mods). The rest of
|
||||
each file keeps its layout.
|
||||
|
||||
Usage:
|
||||
python scripts/bump_version.py # 1.0 -> 1.1
|
||||
python scripts/bump_version.py --major # 1.4 -> 2.0, only when the user says so
|
||||
python scripts/bump_version.py --show # print the version
|
||||
"""
|
||||
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
MOD_JSON = ROOT / "mod.json"
|
||||
VERSION = re.compile(r"^(\d+)\.(\d+)$")
|
||||
JSON_VERSION = re.compile(r'("version"\s*:\s*")([^"]*)(")')
|
||||
# (file below src/<folder>, its version line, how the error names the line)
|
||||
SCRIPTS = [
|
||||
(Path("Scripts") / "main.lua", re.compile(r'^(local VERSION = ")([^"]*)(")', re.MULTILINE),
|
||||
'local VERSION = "<major>.<minor>"'),
|
||||
(Path("main.js"), re.compile(r'^(const [A-Z][A-Z0-9_]*VERSION = ")([^"]*)(";)', re.MULTILINE),
|
||||
'const <NAME>_VERSION = "<major>.<minor>";'),
|
||||
]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
text = MOD_JSON.read_text(encoding="utf-8")
|
||||
mod = json.loads(text)
|
||||
current = mod["version"]
|
||||
match = VERSION.match(current)
|
||||
if not match:
|
||||
sys.exit(f'mod.json: version "{current}" is not <major>.<minor>')
|
||||
found = []
|
||||
for relative, pattern, shown in SCRIPTS:
|
||||
path = ROOT / "src" / mod["folder"] / relative
|
||||
if not path.is_file():
|
||||
continue
|
||||
script = path.read_text(encoding="utf-8")
|
||||
script_match = pattern.search(script)
|
||||
if script_match is None:
|
||||
sys.exit(f"{path}: no line '{shown}'")
|
||||
if script_match.group(2) != current:
|
||||
sys.exit(f"Versions differ: mod.json {current}, {relative.name} {script_match.group(2)}. Make them equal first.")
|
||||
found.append((path, pattern, script))
|
||||
|
||||
if "--show" in sys.argv:
|
||||
print(current)
|
||||
return
|
||||
|
||||
major, minor = int(match.group(1)), int(match.group(2))
|
||||
new = f"{major + 1}.0" if "--major" in sys.argv else f"{major}.{minor + 1}"
|
||||
MOD_JSON.write_text(JSON_VERSION.sub(lambda m: m.group(1) + new + m.group(3), text, count=1),
|
||||
encoding="utf-8", newline="\n")
|
||||
for path, pattern, script in found:
|
||||
path.write_text(pattern.sub(lambda m: m.group(1) + new + m.group(3), script, count=1),
|
||||
encoding="utf-8", newline="\n")
|
||||
print(f"Version {current} -> {new}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,322 @@
|
||||
"use strict";
|
||||
// Simple Power for Phantom Blade Zero: a PBZModLoader mod (ProjectPBZ/PBZModLoader/mods/phantombladezero_simplepower/).
|
||||
//
|
||||
// The player's attacks deal more health damage (attribute Attack) and more Sha-Chi damage (attribute ShachiAttack), and
|
||||
// the player's parries deal more Sha-Chi damage (attribute Amplification_ReflectShachi), each with its own
|
||||
// multiplier. Parries need their own: the game takes a share of the enemy's Sha-Chi bar there, without ShachiAttack. The mod puts the game's own timed attribute effects GE_MA_Attack_0_Mul, GE_MA_ShachiAttack_0_Mul
|
||||
// (operation Multiplicitive) and GE_MA_Amplification_ReflectShachi_0_Add (operation Additive: the amplification is a
|
||||
// share on top, 0 in the game, 0.5 = 50% more, as the game's own Sha-Chi accessory adds 0.05 or 0.1) on the player
|
||||
// character's ability system, all HasDuration with the SetByCaller magnitude "AttributeOpMagnitude", the way Faster
|
||||
// Movement does it for the movement speeds. A timed effect changes the attribute's current value only: base values, and
|
||||
// so the save, stay the game's own. Enemies get no effect.
|
||||
// The poll puts an effect back when the game cleared it (death, load) and replaces it when its multiplier changes.
|
||||
//
|
||||
// PBZModLoader loads this file after the game's MainStart, through the game's module system: require("ue"),
|
||||
// require("puerts") and require("Library/TsHelper") are the game's modules. Before a reload (Alt+F5) it awaits stop(),
|
||||
// which takes the effects off (restore()).
|
||||
// Settings: phantombladezero_simplepower.txt next to this file (__dirname), "Key=Value" lines (; or # starts a comment,
|
||||
// the first line of a key wins), read every SETTINGS_MS and written with the defaults when missing. With Mods Menu
|
||||
// (0.9.0 or later) running, the mod adds its page there and reads the file that page saves instead (a page cannot save
|
||||
// anywhere else).
|
||||
const UE = require("ue");
|
||||
const puerts = require("puerts");
|
||||
|
||||
const MOD_NAME = "Simple Power";
|
||||
const MOD_ID = "phantombladezero_simplepower"; // the mod folder's name and Mods Menu's page id
|
||||
const MOD_VERSION = "1.2";
|
||||
const POLL_MS = 500;
|
||||
const SETTINGS_MS = 2000;
|
||||
const SETTINGS_FILE = MOD_ID + ".txt";
|
||||
const MULTIPLIER_MIN = 0.1, MULTIPLIER_MAX = 10, MULTIPLIER_DEFAULT = 1.5;
|
||||
// Timed, never 0: a duration of 0 or less might fall back to the instant effect (_1_), which writes the base value.
|
||||
const EFFECT_SECONDS = 1000000;
|
||||
// A poll that throws is tried again (a level load can free an object halfway); this many in a row end the mod.
|
||||
const MAX_ERRORS = 10;
|
||||
// loader.log takes a limited number of lines: at most this many about the effects per start.
|
||||
const MAX_LOGS = 30;
|
||||
// Each setting (a multiplier m): its attribute (UBasicAttributeSet), the operation of the game's effect, the magnitude
|
||||
// for m, and the attribute that is above 0 once the game set the character up (an amplification is 0 in the game).
|
||||
const POWERS = [
|
||||
{ setting: "Attack", attribute: "Attack", op: "Mul", magnitude: (m) => m, ready: "Attack" },
|
||||
{ setting: "ShaChiAttack", attribute: "ShachiAttack", op: "Mul", magnitude: (m) => m, ready: "ShachiAttack" },
|
||||
{ setting: "ParryShaChi", attribute: "Amplification_ReflectShachi", op: "Add", magnitude: (m) => m - 1, ready: "Attack" },
|
||||
];
|
||||
const effectName = (power) => `GE_MA_${power.attribute}_0_${power.op}`;
|
||||
const effectPath = (power) => `/PBZCombatAsset/Config/AttributesModifyEffect/${effectName(power)}.${effectName(power)}`;
|
||||
// Every setting with its default; the shipped settings file holds exactly this text (tests/test_mod.js checks it).
|
||||
const DEFAULT_TEXT = ["; " + MOD_NAME + " settings. Change a value and save; the game picks it up within 2 seconds.",
|
||||
"; Enable: On, or Off (the mod does nothing).",
|
||||
"Enable=On",
|
||||
"; Attack: the health damage you deal, 0.1 to 10. 1 = the game's own, 1.5 = 50% more, 2 = double.",
|
||||
"Attack=1.5",
|
||||
"; ShaChiAttack: the Sha-Chi damage your hits deal, 0.1 to 10. 1 = the game's own, 1.5 = 50% more, 2 = double.",
|
||||
"ShaChiAttack=1.5",
|
||||
"; ParryShaChi: the Sha-Chi damage your parries deal, 0.1 to 10. 1 = the game's own, 2 = double.",
|
||||
"ParryShaChi=1.5", ""].join("\r\n");
|
||||
|
||||
// The running poll, its GameInstance, the settings file, the settings, polls that threw in a row, lines logged; off:
|
||||
// the mod ended itself at once (a base value moved).
|
||||
const run = { timer: undefined, ctx: undefined, path: undefined, readAt: -Infinity, made: false, errors: 0, logs: 0,
|
||||
off: false, settings: { enable: true, Attack: MULTIPLIER_DEFAULT, ShaChiAttack: MULTIPLIER_DEFAULT,
|
||||
ParryShaChi: MULTIPLIER_DEFAULT } };
|
||||
// Our effects: character path name -> { asc, buffs: { setting: { m, handle } } }. A string key, so a new JS wrapper
|
||||
// for the same actor cannot get a second effect.
|
||||
const players = new Map();
|
||||
const effects = {};
|
||||
|
||||
// The Mods Menu page (optional): one row per setting, the same keys and defaults as DEFAULT_TEXT.
|
||||
const page = () => ({ id: MOD_ID, title: MOD_NAME, version: MOD_VERSION, file: SETTINGS_FILE, store: "saved",
|
||||
description: { en: "Your attacks deal more health and Sha-Chi damage, your parries more Sha-Chi damage. Enemies are not changed." },
|
||||
settings: [
|
||||
{ key: "Enable", type: "toggle", label: "Enable", default: true, help: "Off: the mod does nothing." },
|
||||
{ key: "Attack", type: "number", label: "Attack", min: MULTIPLIER_MIN, max: MULTIPLIER_MAX, step: 0.1,
|
||||
default: MULTIPLIER_DEFAULT, help: "The health damage you deal. 1 is the game's own, 2 is double." },
|
||||
{ key: "ShaChiAttack", type: "number", label: "Sha-Chi Attack", min: MULTIPLIER_MIN, max: MULTIPLIER_MAX,
|
||||
step: 0.1, default: MULTIPLIER_DEFAULT,
|
||||
help: "The Sha-Chi damage your hits deal. 1 is the game's own, 2 is double." },
|
||||
{ key: "ParryShaChi", type: "number", label: "Parry Sha-Chi", min: MULTIPLIER_MIN, max: MULTIPLIER_MAX,
|
||||
step: 0.1, default: MULTIPLIER_DEFAULT,
|
||||
help: "The Sha-Chi damage your parries deal. 1 is the game's own, 2 is double." },
|
||||
],
|
||||
onChange: () => { run.readAt = -Infinity; } }); // the next poll reads the file
|
||||
// PBZModLoader starts its mods after Mods Menu's, so a running Mods Menu has its registry object here by now. Without it
|
||||
// nothing is pushed: an array left for a Mods Menu that starts later would give a page that saves another file.
|
||||
const menu = { on: false };
|
||||
{
|
||||
const mm = globalThis.PBZModsMenu;
|
||||
if (mm && typeof mm === "object" && !Array.isArray(mm) && typeof mm.push === "function"
|
||||
&& typeof mm.settingsPath === "function" && mm.api && typeof mm.api.has === "function"
|
||||
&& mm.api.has("settingsPath") && mm.api.has("store.saved")) {
|
||||
try {
|
||||
mm.push(page());
|
||||
menu.on = typeof mm.settingsPath(MOD_ID) === "string";
|
||||
}
|
||||
catch (e) {
|
||||
console.warn(`[${MOD_NAME}] no Mods Menu page: ${e}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The settings file: the one Mods Menu's page saves, else the one next to this main.js.
|
||||
function settingsPath() {
|
||||
if (menu.on) {
|
||||
const path = globalThis.PBZModsMenu.settingsPath(MOD_ID);
|
||||
if (typeof path === "string" && path)
|
||||
return path;
|
||||
}
|
||||
return UE.KismetSystemLibrary.ConvertToAbsolutePath(String(__dirname).replace(/[\\/]+$/, "") + "/" + SETTINGS_FILE);
|
||||
}
|
||||
|
||||
// The value of `key` in the settings text, in lower case ("" when the key is missing).
|
||||
function readKey(text, key) {
|
||||
const re = new RegExp("^[ \\t]*" + key + "[ \\t]*=[ \\t]*([^;#\\r\\n]*?)[ \\t]*(?:[;#][^\\r\\n]*)?$", "i");
|
||||
for (const line of text.split(/\r?\n/)) {
|
||||
const m = re.exec(line);
|
||||
if (m)
|
||||
return m[1].toLowerCase();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// A multiplier from the settings text, also "1,5" and "x2", clamped: the default when the key is missing or empty, the
|
||||
// last value when it is not a number.
|
||||
function readMultiplier(text, key, last) {
|
||||
const value = readKey(text, key);
|
||||
if (value === "")
|
||||
return MULTIPLIER_DEFAULT;
|
||||
const m = /^x?[ \t]*([+-]?(?:\d+(?:[.,]\d*)?|[.,]\d+))$/.exec(value);
|
||||
return m ? Math.min(MULTIPLIER_MAX, Math.max(MULTIPLIER_MIN, parseFloat(m[1].replace(",", ".")))) : last;
|
||||
}
|
||||
|
||||
// Reads the settings file at most every SETTINGS_MS. A file that cannot be read keeps the last settings.
|
||||
function readSettings() {
|
||||
if (Math.abs(Date.now() - run.readAt) < SETTINGS_MS)
|
||||
return;
|
||||
run.readAt = Date.now();
|
||||
try {
|
||||
run.path = run.path || settingsPath();
|
||||
let text = "";
|
||||
if (UE.BlueprintPathsLibrary.FileExists(run.path)) { // check first: EasyCsv logs an error for a missing file
|
||||
const out = puerts.$ref("");
|
||||
if (!UE.EasyCsv.LoadStringFromLocalFile(run.path, out))
|
||||
return; // locked mid-save, or 10 characters or fewer: keep the last settings
|
||||
text = String(puerts.$unref(out)).replace(/^/, "");
|
||||
}
|
||||
else if (!run.made) {
|
||||
run.made = true; // once a session, and never over an existing file
|
||||
UE.EasyCsv.SaveStringToFileWithFullPath(DEFAULT_TEXT, run.path);
|
||||
}
|
||||
run.settings.enable = !["off", "0", "no", "false"].includes(readKey(text, "Enable"));
|
||||
for (const { setting } of POWERS)
|
||||
run.settings[setting] = readMultiplier(text, setting, run.settings[setting]);
|
||||
}
|
||||
catch (e) {
|
||||
console.warn(`[${MOD_NAME}] settings not read: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Puerts throws for an object the game freed, also inside IsValid.
|
||||
function valid(object) {
|
||||
try {
|
||||
return !!object && UE.KismetSystemLibrary.IsValid(object);
|
||||
}
|
||||
catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const alive = (buff) => UE.AbilitySystemBlueprintLibrary.GetActiveGameplayEffectStackCount(buff.handle) > 0;
|
||||
const attribute = (name) => UE.PBZBlueprintFunctionLibrary.MakeAttribute(name, UE.BasicAttributeSet.StaticClass());
|
||||
const baseValue = (character, attr) =>
|
||||
UE.AbilitySystemBlueprintLibrary.GetFloatAttributeBase(character, attr, puerts.$ref(false));
|
||||
const currentValue = (character, attr) => UE.PBZBlueprintFunctionLibrary.GetAttributeFromCharacter(character, attr);
|
||||
const shown = (value) => String(+value.toFixed(2));
|
||||
|
||||
function log(message) {
|
||||
if (run.logs++ < MAX_LOGS)
|
||||
console.log(`[PBZMOD] [${MOD_NAME}] ${message}`);
|
||||
}
|
||||
|
||||
// Takes one effect off. Its record goes only when the effect is gone, so a call that throws is tried again.
|
||||
function remove(record, name) {
|
||||
const buff = record.buffs[name];
|
||||
if (!buff)
|
||||
return;
|
||||
if (alive(buff)) {
|
||||
record.asc.RemoveActiveGameplayEffect(buff.handle, -1);
|
||||
if (alive(buff))
|
||||
throw new Error(`the game did not take the ${name} effect off`);
|
||||
}
|
||||
delete record.buffs[name];
|
||||
}
|
||||
|
||||
// Puts one power's effect on the player, replaces it, or takes it off (a multiplier of 1).
|
||||
function apply(character, record, power, m) {
|
||||
const name = power.setting;
|
||||
const old = record.buffs[name];
|
||||
if (old ? old.m === m && alive(old) : m === 1)
|
||||
return;
|
||||
remove(record, name); // the multiplier changed, or the game cleared ours: never two at once
|
||||
const attr = attribute(power.attribute);
|
||||
const before = currentValue(character, attr);
|
||||
if (m === 1) {
|
||||
log(`${name}: the game's own, ${power.attribute} ${shown(before)}`);
|
||||
return;
|
||||
}
|
||||
if (!(currentValue(character, attribute(power.ready)) > 0))
|
||||
return; // the character's attributes are not set up yet (spawn, load): the next poll tries again
|
||||
const effect = effects[name] = effects[name] || UE.Object.Load(effectPath(power));
|
||||
if (!effect)
|
||||
throw new Error(`the game's effect ${effectName(power)} is missing`);
|
||||
const ASC = UE.AbilitySystemBlueprintLibrary;
|
||||
const base = baseValue(character, attr);
|
||||
// AttributeUtils.AddAttributeBuff ran as an instant effect in game (Faster Movement's source), so the timed spec is
|
||||
// built by hand: the game's own HasDuration effect, SetByCaller magnitude, locked duration.
|
||||
let spec = ASC.MakeSpecHandle(effect, character, character, 1);
|
||||
spec = ASC.AssignSetByCallerMagnitude(spec, "AttributeOpMagnitude", power.magnitude(m));
|
||||
spec = ASC.SetDuration(spec, EFFECT_SECONDS);
|
||||
const buff = record.buffs[name] = { m, handle: record.asc.BP_ApplyGameplayEffectSpecToSelf(spec) };
|
||||
if (baseValue(character, attr) !== base) {
|
||||
// The effect landed on the base value, which the save may keep and the next poll would multiply again: put the
|
||||
// base back and end the mod for this session.
|
||||
run.off = true;
|
||||
UE.AttributeUtils.ModifyCharacterAttributeValue(character, attr, UE.EGameplayModOp.Override, base);
|
||||
throw new Error(`${power.attribute}: the base value moved from ${shown(base)} and was put back`);
|
||||
}
|
||||
if (!alive(buff)) {
|
||||
delete record.buffs[name]; // the game refused it: the next poll tries again
|
||||
return;
|
||||
}
|
||||
log(`${name} x${m}: ${power.attribute} ${shown(before)} -> ${shown(currentValue(character, attr))}`);
|
||||
}
|
||||
|
||||
// Puts the wanted effects on the player character, once per poll.
|
||||
function step(ctx) {
|
||||
const character = UE.GameplayStatics.GetPlayerCharacter(ctx, 0);
|
||||
if (!valid(character))
|
||||
return;
|
||||
const asc = UE.AbilitySystemBlueprintLibrary.GetAbilitySystemComponent(character);
|
||||
if (!valid(asc))
|
||||
return; // not set up yet (spawn, load): the next poll tries again
|
||||
for (const [key, record] of players)
|
||||
if (!valid(record.asc))
|
||||
players.delete(key); // that character is gone, and its effects with it
|
||||
const key = UE.KismetSystemLibrary.GetPathName(character);
|
||||
let record = players.get(key);
|
||||
if (!record)
|
||||
players.set(key, record = { asc, buffs: {} });
|
||||
record.asc = asc; // a new character can have an old one's path name; the old handles are then no longer alive
|
||||
for (const power of POWERS)
|
||||
apply(character, record, power, run.settings[power.setting]);
|
||||
}
|
||||
|
||||
// Takes every effect off (Enable=Off, stop(), an error). An effect that stays keeps its record for the next try; the
|
||||
// first error is thrown once all were tried.
|
||||
function restore() {
|
||||
let problem = undefined;
|
||||
for (const [key, record] of players) {
|
||||
if (!valid(record.asc)) {
|
||||
players.delete(key);
|
||||
continue;
|
||||
}
|
||||
for (const name of Object.keys(record.buffs)) {
|
||||
try {
|
||||
remove(record, name);
|
||||
}
|
||||
catch (e) {
|
||||
problem = problem || e;
|
||||
}
|
||||
}
|
||||
if (Object.keys(record.buffs).length === 0)
|
||||
players.delete(key);
|
||||
}
|
||||
if (problem)
|
||||
throw problem;
|
||||
}
|
||||
|
||||
function poll() {
|
||||
readSettings();
|
||||
try {
|
||||
if (run.settings.enable)
|
||||
step(run.ctx);
|
||||
else
|
||||
restore();
|
||||
run.errors = 0;
|
||||
}
|
||||
catch (e) {
|
||||
if (++run.errors < MAX_ERRORS && !run.off)
|
||||
return; // a level load can free an object between two calls: the next poll tries again
|
||||
// a class or function is gone after a game update: stop for the session and leave the game as it is
|
||||
clearInterval(run.timer);
|
||||
run.timer = undefined;
|
||||
console.warn(`[${MOD_NAME}] stopped: ${e}`);
|
||||
try { restore(); } catch (e2) { }
|
||||
}
|
||||
}
|
||||
|
||||
// Start at once. A start that fails throws, so PBZModLoader logs the mod as failed.
|
||||
try {
|
||||
run.ctx = puerts.argv.getByName("GameInstance");
|
||||
if (!run.ctx)
|
||||
throw new Error("the GameInstance is missing");
|
||||
readSettings();
|
||||
run.timer = setInterval(poll, POLL_MS);
|
||||
console.log(`[PBZMOD] [${MOD_NAME}] ${MOD_VERSION} started; settings: ${run.path}` + (menu.on ? " (Mods Menu's page)" : ""));
|
||||
}
|
||||
catch (e) {
|
||||
console.warn(`[${MOD_NAME}] not started: ${e}`);
|
||||
throw e;
|
||||
}
|
||||
|
||||
exports.stop = function () {
|
||||
if (run.timer !== undefined)
|
||||
clearInterval(run.timer);
|
||||
run.timer = undefined;
|
||||
try {
|
||||
restore();
|
||||
}
|
||||
catch (e) {
|
||||
console.warn(`[${MOD_NAME}] stop: ${e}`);
|
||||
}
|
||||
console.log(`[PBZMOD] [${MOD_NAME}] stopped`);
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
; Simple Power settings. Change a value and save; the game picks it up within 2 seconds.
|
||||
; Enable: On, or Off (the mod does nothing).
|
||||
Enable=On
|
||||
; Attack: the health damage you deal, 0.1 to 10. 1 = the game's own, 1.5 = 50% more, 2 = double.
|
||||
Attack=1.5
|
||||
; ShaChiAttack: the Sha-Chi damage your hits deal, 0.1 to 10. 1 = the game's own, 1.5 = 50% more, 2 = double.
|
||||
ShaChiAttack=1.5
|
||||
; ParryShaChi: the Sha-Chi damage your parries deal, 0.1 to 10. 1 = the game's own, 2 = double.
|
||||
ParryShaChi=1.5
|
||||
@@ -0,0 +1,509 @@
|
||||
// Offline test of the mod, run by build.ps1: node tests/test_mod.js
|
||||
// It loads src/phantombladezero_simplepower/main.js as PBZModLoader does (a module whose __dirname is the mod's folder) with
|
||||
// stand-ins for the modules the game gives it (ue, puerts, the game's TsHelper), an optional running Mods Menu and the
|
||||
// settings file, drives the mod's poll and the clock by hand, and checks what the mod does.
|
||||
"use strict";
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const Module = require("module");
|
||||
|
||||
const FOLDER = path.join(__dirname, "..", "src", "phantombladezero_simplepower");
|
||||
const SCRIPT = path.join(FOLDER, "main.js");
|
||||
const SETTINGS = path.join(FOLDER, "phantombladezero_simplepower.txt");
|
||||
// The mod's own settings path: __dirname of main.js and the file name (ConvertToAbsolutePath is a stand-in here).
|
||||
const SETTINGS_PATH = FOLDER.replace(/[\\/]+$/, "") + "/phantombladezero_simplepower.txt";
|
||||
const MENU_PATH = "C:/Game/ProjectPBZ/Saved/PBZModsMenu/Settings/phantombladezero_simplepower.txt";
|
||||
|
||||
let failed = 0;
|
||||
function check(name, ok) {
|
||||
console.log(`${ok ? "ok " : "FAIL"} ${name}`);
|
||||
if (!ok) {
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
|
||||
// A running Mods Menu as the mod meets it (its registry object), or without the features named in `missing`.
|
||||
function modsMenu(world, missing = []) {
|
||||
return {
|
||||
api: { has: (feature) => !missing.includes(feature) },
|
||||
push(...mods) { world.pushed.push(...mods); return world.pushed.length; },
|
||||
settingsPath: (id) => (world.pushed.some((m) => m.id == id) ? MENU_PATH : undefined),
|
||||
};
|
||||
}
|
||||
|
||||
// The game's ability system as the mod meets it. A character holds base values and active effects; an attribute's
|
||||
// current value is (its base + every added effect) x every multiplied one. A freed object throws in every call, as in Puerts.
|
||||
function character(name, values = { Attack: 100, ShachiAttack: 80, Amplification_ReflectShachi: 0, Health: 850 }) {
|
||||
const c = { path: name, base: { ...values }, active: [], freed: false, removed: [] };
|
||||
c.asc = {
|
||||
owner: c,
|
||||
BP_ApplyGameplayEffectSpecToSelf(spec) {
|
||||
if (c.refuse) {
|
||||
return { on: false };
|
||||
}
|
||||
if (c.instant) {
|
||||
c.base[spec.attr] *= spec.m;
|
||||
return { on: false };
|
||||
}
|
||||
const handle = { on: true, attr: spec.attr, op: spec.op, m: spec.m, seconds: spec.seconds };
|
||||
c.active.push(handle);
|
||||
return handle;
|
||||
},
|
||||
RemoveActiveGameplayEffect(handle, stacks) {
|
||||
if (c.freed || c.stuck) {
|
||||
throw new Error("stuck");
|
||||
}
|
||||
c.removed.push([handle, stacks]);
|
||||
if (!c.keeps && c.active.includes(handle)) {
|
||||
handle.on = false;
|
||||
c.active.splice(c.active.indexOf(handle), 1);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
};
|
||||
const sum = (attr) => c.active.filter((h) => h.attr == attr && h.op == "Add").reduce((v, h) => v + h.m, c.base[attr]);
|
||||
c.value = (attr) => c.active.filter((h) => h.attr == attr && h.op == "Mul").reduce((v, h) => v * h.m, sum(attr));
|
||||
c.clear = () => { c.active.forEach((h) => { h.on = false; }); c.active = []; }; // death, load
|
||||
c.free = () => { c.clear(); c.freed = true; };
|
||||
return c;
|
||||
}
|
||||
|
||||
function addGame(world, ue, options) {
|
||||
const alive = (o) => {
|
||||
if ((o.owner || o).freed) {
|
||||
throw new Error("passing a invalid object");
|
||||
}
|
||||
return true;
|
||||
};
|
||||
world.player = "player" in options ? options.player : character("/Game/Map.Hun_1");
|
||||
world.enemy = character("/Game/Map.Enemy_1");
|
||||
world.loaded = [];
|
||||
world.ctxSeen = [];
|
||||
ue.KismetSystemLibrary.IsValid = (o) => !!o && alive(o);
|
||||
ue.KismetSystemLibrary.GetPathName = (o) => alive(o) && o.path;
|
||||
ue.GameplayStatics = { GetPlayerCharacter: (ctx, index) => {
|
||||
world.ctxSeen.push([ctx, index]);
|
||||
if (world.throws) {
|
||||
throw new Error("boom");
|
||||
}
|
||||
return world.player;
|
||||
} };
|
||||
ue.BasicAttributeSet = { StaticClass: () => "BasicAttributeSet" };
|
||||
ue.PBZBlueprintFunctionLibrary = {
|
||||
MakeAttribute: (name, set) => ({ name, set }),
|
||||
GetAttributeFromCharacter: (c, attr) => (alive(c) && attr.set == "BasicAttributeSet" ? c.value(attr.name) : NaN),
|
||||
};
|
||||
ue.Object = { Load(p) {
|
||||
world.loaded.push(p);
|
||||
const m = /^\/PBZCombatAsset\/Config\/AttributesModifyEffect\/(GE_MA_(\w+)_0_(Mul|Add))\.\1$/.exec(p);
|
||||
return m && !options.noEffects ? { attr: m[2], op: m[3] } : undefined;
|
||||
} };
|
||||
ue.AbilitySystemBlueprintLibrary = {
|
||||
GetAbilitySystemComponent: (c) => (alive(c) && !c.noAsc ? c.asc : undefined),
|
||||
GetActiveGameplayEffectStackCount: (handle) => (handle.on ? 1 : 0),
|
||||
GetFloatAttributeBase: (c, attr, ok) => { ok[0] = true; return c.base[attr.name]; },
|
||||
MakeSpecHandle: (effect, instigator, causer, level) => ({ attr: effect.attr, op: effect.op, instigator, causer, level, m: 0, seconds: 0 }),
|
||||
AssignSetByCallerMagnitude: (spec, name, m) => ({ ...spec, m: name == "AttributeOpMagnitude" ? m : 0 }),
|
||||
SetDuration: (spec, seconds) => ({ ...spec, seconds }),
|
||||
};
|
||||
ue.EGameplayModOp = { Override: 3 };
|
||||
ue.AttributeUtils = { ModifyCharacterAttributeValue(c, attr, op, value) {
|
||||
if (op === 3) {
|
||||
c.base[attr.name] = value;
|
||||
}
|
||||
} };
|
||||
}
|
||||
|
||||
// One fresh load of the script with its own stand-in game.
|
||||
function boot(options = {}) {
|
||||
const world = { now: 1000000, files: new Map(), saved: [], warnings: [], logs: [], pushed: [], timer: undefined,
|
||||
interval: undefined, cleared: false, loadError: undefined };
|
||||
if (options.settings !== undefined) {
|
||||
world.files.set(options.settingsPath || SETTINGS_PATH, options.settings);
|
||||
}
|
||||
const gameInstance = { path: "/Engine/Transient.GameInstance" };
|
||||
const ue = {
|
||||
KismetSystemLibrary: { IsValid: (o) => !!o, ConvertToAbsolutePath: (p) => p, GetPathName: (o) => o.path },
|
||||
BlueprintPathsLibrary: { FileExists: (p) => world.files.has(p) },
|
||||
EasyCsv: {
|
||||
LoadStringFromLocalFile(p, out) { out[0] = world.files.get(p); return true; },
|
||||
SaveStringToFileWithFullPath(text, p) { world.saved.push([p, text]); world.files.set(p, text); },
|
||||
},
|
||||
};
|
||||
addGame(world, ue, options);
|
||||
const puerts = {
|
||||
$ref: (value) => [value],
|
||||
$unref: (box) => box[0],
|
||||
argv: { getByName: (name) => (name == "GameInstance" && !options.noGameInstance ? gameInstance : undefined) },
|
||||
};
|
||||
const stubs = { "ue": ue, "puerts": puerts, "Library/TsHelper": { default: {} } };
|
||||
// the game's modules, also for a require() that the mod runs later inside a timer
|
||||
const load = Module._load;
|
||||
const hooked = function (request, parent, isMain) {
|
||||
if (Object.prototype.hasOwnProperty.call(stubs, request)) {
|
||||
return stubs[request];
|
||||
}
|
||||
return load.call(this, request, parent, isMain);
|
||||
};
|
||||
const realNow = Date.now, realWarn = console.warn, realLog = console.log;
|
||||
const enter = () => {
|
||||
Module._load = hooked;
|
||||
Date.now = () => world.now;
|
||||
console.warn = (message) => world.warnings.push(String(message));
|
||||
console.log = (message) => world.logs.push(String(message));
|
||||
};
|
||||
const leave = () => {
|
||||
Module._load = load;
|
||||
Date.now = realNow;
|
||||
console.warn = realWarn;
|
||||
console.log = realLog;
|
||||
};
|
||||
globalThis.setInterval = (fn, ms) => { world.timer = fn; world.interval = ms; return 9; };
|
||||
globalThis.clearInterval = (id) => { world.cleared = id === 9; };
|
||||
globalThis.PBZModsMenu = options.menu === "array" ? [] : options.menu ? modsMenu(world, options.menuMissing) : undefined;
|
||||
world.menuGlobal = globalThis.PBZModsMenu;
|
||||
delete require.cache[require.resolve(SCRIPT)];
|
||||
enter();
|
||||
try {
|
||||
world.exports = require(SCRIPT);
|
||||
}
|
||||
catch (e) {
|
||||
world.loadError = e;
|
||||
}
|
||||
finally {
|
||||
leave();
|
||||
}
|
||||
world.poll = (ms = world.interval) => {
|
||||
world.now += ms;
|
||||
enter();
|
||||
try {
|
||||
world.timer();
|
||||
}
|
||||
finally {
|
||||
leave();
|
||||
}
|
||||
};
|
||||
world.stop = () => {
|
||||
enter();
|
||||
try {
|
||||
world.exports.stop();
|
||||
}
|
||||
finally {
|
||||
leave();
|
||||
}
|
||||
};
|
||||
return world;
|
||||
}
|
||||
|
||||
// The module as PBZModLoader loads it.
|
||||
{
|
||||
const w = boot();
|
||||
check("no error at load; stop() exported; one poll timer", !w.loadError && typeof w.exports.stop == "function"
|
||||
&& typeof w.timer == "function");
|
||||
check("one start line for loader.log, naming the settings file in the mod's folder",
|
||||
w.logs.length == 1 && w.logs[0].startsWith("[PBZMOD] [") && w.logs[0].endsWith(`started; settings: ${SETTINGS_PATH}`));
|
||||
check("no Mods Menu: no page pushed anywhere", globalThis.PBZModsMenu === undefined && w.pushed.length == 0);
|
||||
}
|
||||
|
||||
// The settings file.
|
||||
{
|
||||
const w = boot();
|
||||
const shipped = fs.readFileSync(SETTINGS, "utf8");
|
||||
check("a missing settings file is written once at the start, in the mod's folder, with the shipped text (CRLF)",
|
||||
w.saved.length == 1 && w.saved[0][0] == SETTINGS_PATH && w.saved[0][1] == shipped && shipped.includes("\r\n"));
|
||||
const kept = boot({ settings: "Enable=Off\r\n" });
|
||||
check("an existing settings file is never written over", kept.saved.length == 0);
|
||||
}
|
||||
|
||||
// Mods Menu: optional.
|
||||
{
|
||||
const m = boot({ menu: true });
|
||||
const page = m.pushed[0];
|
||||
check("Mods Menu running: one page with the mod's id and store \"saved\"", m.pushed.length == 1
|
||||
&& page.id == "phantombladezero_simplepower" && page.store == "saved" && typeof page.onChange == "function");
|
||||
check("... and the mod reads the file the page saves", m.saved.length == 1 && m.saved[0][0] == MENU_PATH
|
||||
&& m.logs[0].endsWith(`settings: ${MENU_PATH} (Mods Menu's page)`));
|
||||
const a = boot({ menu: "array" });
|
||||
check("Mods Menu not started yet (a plain array): nothing pushed, the mod's own file",
|
||||
a.menuGlobal.length == 0 && a.saved[0][0] == SETTINGS_PATH);
|
||||
const o = boot({ menu: true, menuMissing: ["store.saved"] });
|
||||
check("an older Mods Menu without store \"saved\": no page, the mod's own file",
|
||||
o.pushed.length == 0 && o.saved[0][0] == SETTINGS_PATH);
|
||||
}
|
||||
|
||||
// The effects on the player.
|
||||
const near = (a, b) => Math.abs(a - b) < 1e-9;
|
||||
const powers = (w) => [w.player.value("Attack"), w.player.value("ShachiAttack")];
|
||||
const parry = (w) => w.player.value("Amplification_ReflectShachi");
|
||||
// The checks below are about Attack and ShachiAttack (parry at 1, no effect) unless they name parry.
|
||||
const is = (w, attack, shachi, amplification = undefined) => near(powers(w)[0], attack) && near(powers(w)[1], shachi)
|
||||
&& (amplification === undefined || near(parry(w), amplification));
|
||||
const text = (attack, shachi, enable = "On", parryValue = 1) =>
|
||||
`Enable=${enable}\r\nAttack=${attack}\r\nShaChiAttack=${shachi}\r\nParryShaChi=${parryValue}\r\n`;
|
||||
function setText(w, value, p = SETTINGS_PATH) {
|
||||
w.files.set(p, value);
|
||||
w.poll(2000); // the next read of the file
|
||||
}
|
||||
{
|
||||
const w = boot();
|
||||
w.poll();
|
||||
check("defaults: Attack and ShachiAttack x1.5, the parry amplification +0.5 on the player", is(w, 150, 120, 0.5));
|
||||
check("three timed effects of 1,000,000 s; nothing else of the player changed", w.player.active.length == 3
|
||||
&& w.player.active.every((h) => h.seconds === 1000000) && w.player.value("Health") == 850);
|
||||
check("base values stay the game's own", w.player.base.Attack == 100 && w.player.base.ShachiAttack == 80
|
||||
&& w.player.base.Amplification_ReflectShachi === 0);
|
||||
check("enemies get no effect", w.enemy.active.length == 0);
|
||||
check("the player of the GameInstance, index 0", w.ctxSeen.every(([c, i]) => c.path.includes("GameInstance") && i === 0));
|
||||
check("one log line per effect with the value before and after", w.logs.length == 4
|
||||
&& w.logs[1] == "[PBZMOD] [Simple Power] Attack x1.5: Attack 100 -> 150"
|
||||
&& w.logs[2] == "[PBZMOD] [Simple Power] ShaChiAttack x1.5: ShachiAttack 80 -> 120"
|
||||
&& w.logs[3] == "[PBZMOD] [Simple Power] ParryShaChi x1.5: Amplification_ReflectShachi 0 -> 0.5");
|
||||
for (let i = 0; i < 50; i++) {
|
||||
w.poll();
|
||||
}
|
||||
check("50 more polls: no second effect, no new line", is(w, 150, 120, 0.5) && w.player.active.length == 3 && w.logs.length == 4);
|
||||
check("each effect asset loaded once", w.loaded.length == 3);
|
||||
}
|
||||
|
||||
// The multipliers.
|
||||
{
|
||||
const w = boot({ settings: text(2, 3) });
|
||||
w.poll();
|
||||
check("Attack=2, ShaChiAttack=3: each with its own multiplier", is(w, 200, 240));
|
||||
const shachi = w.player.active.find((h) => h.attr == "ShachiAttack");
|
||||
setText(w, text(4, 3));
|
||||
check("a changed file is used live, and the old effect is replaced (never two)", is(w, 400, 240) && w.player.active.length == 2);
|
||||
check("... and the other effect is not touched", w.player.active.includes(shachi));
|
||||
setText(w, text(1, 3));
|
||||
check("1 takes that effect off", is(w, 100, 240) && w.player.active.length == 1
|
||||
&& w.logs[w.logs.length - 1].endsWith("Attack: the game's own, Attack 100"));
|
||||
const lines = w.logs.length;
|
||||
w.poll();
|
||||
check("1 stays quiet afterwards", w.logs.length == lines && w.player.active.length == 1);
|
||||
setText(w, text(0.5, 0.5));
|
||||
check("below 1 weakens", is(w, 50, 40));
|
||||
setText(w, text(0, 99));
|
||||
check("clamped to 0.1 and 10", is(w, 10, 800));
|
||||
setText(w, text("-5", "1,5"));
|
||||
check("a negative value is clamped, a decimal comma works", is(w, 10, 120));
|
||||
setText(w, text("x2 ; double", ".5 # half"));
|
||||
check("x2, .5 and comments work", is(w, 200, 40));
|
||||
setText(w, text("abc", "2 3"));
|
||||
check("not a number: the last values stay", is(w, 200, 40));
|
||||
setText(w, "Enable=On\r\nAttack=\r\n");
|
||||
check("an empty or missing key means 1.5 (also a file of 1.0 without ParryShaChi)", is(w, 150, 120, 0.5));
|
||||
setText(w, "attack = 3\nSHACHIATTACK=2\nAttack=9\n");
|
||||
check("a byte order mark, other case, LF, the first line of a key wins", is(w, 300, 160));
|
||||
const s = boot({ settings: text(1, 1) });
|
||||
s.poll();
|
||||
check("all 1: no effect, no asset loaded, no line", s.player.active.length == 0 && s.loaded.length == 0 && s.logs.length == 1);
|
||||
}
|
||||
|
||||
// Blocks and parries.
|
||||
{
|
||||
const w = boot({ settings: text(1, 1, "On", 3) });
|
||||
w.poll();
|
||||
check("ParryShaChi=3: the amplification +2, nothing else", is(w, 100, 80, 2) && w.player.active.length == 1);
|
||||
w.player.base.Amplification_ReflectShachi = 0.1; // the game's accessory
|
||||
check("... on top of the game's own amplification", near(parry(w), 2.1));
|
||||
w.player.base.Amplification_ReflectShachi = 0;
|
||||
setText(w, text(1, 1, "On", 10));
|
||||
check("ParryShaChi=10: +9, the old effect replaced", near(parry(w), 9) && w.player.active.length == 1);
|
||||
setText(w, text(1, 1, "On", 0.1));
|
||||
check("ParryShaChi=0.1: -0.9", near(parry(w), -0.9) && w.player.active.length == 1);
|
||||
setText(w, text(1, 1, "On", 1));
|
||||
check("ParryShaChi=1: no effect", parry(w) === 0 && w.player.active.length == 0);
|
||||
setText(w, text(2, 2, "Off", 4));
|
||||
setText(w, text(2, 2, "On", 4));
|
||||
check("ParryShaChi follows Enable", is(w, 200, 160, 3));
|
||||
setText(w, text(2, 2, "Off", 4));
|
||||
check("... off too", is(w, 100, 80, 0));
|
||||
const n = boot({ settings: text(1, 1, "On", 2) });
|
||||
n.player.base.Attack = 0;
|
||||
n.poll();
|
||||
check("a character that is not set up yet (Attack 0): no amplification yet", n.player.active.length == 0);
|
||||
n.player.base.Attack = 100;
|
||||
n.poll();
|
||||
check("... and it comes at a later poll", near(parry(n), 1));
|
||||
n.stop();
|
||||
check("stop() takes it off", parry(n) === 0);
|
||||
}
|
||||
|
||||
// Enable.
|
||||
{
|
||||
const w = boot({ settings: text(2, 2) });
|
||||
w.poll();
|
||||
setText(w, text(2, 2, "Off"));
|
||||
check("Enable=Off takes both effects off, all stacks", is(w, 100, 80) && w.player.active.length == 0
|
||||
&& w.player.removed.every(([, stacks]) => stacks === -1));
|
||||
setText(w, text(2, 2));
|
||||
check("Enable=On puts them back", is(w, 200, 160));
|
||||
const off = boot({ settings: text(2, 2, "Off") });
|
||||
off.poll();
|
||||
check("Enable=Off from the start: nothing", off.player.active.length == 0 && off.ctxSeen.length == 0);
|
||||
}
|
||||
|
||||
// The player dies, loads, is not there yet.
|
||||
{
|
||||
const w = boot({ player: undefined });
|
||||
for (let n = 0; n < 20; n++) {
|
||||
w.poll();
|
||||
}
|
||||
check("no player (the main menu): quiet", w.warnings.length == 0 && w.timer !== undefined && !w.cleared);
|
||||
w.player = character("/Game/Map.Hun_1");
|
||||
w.player.noAsc = true;
|
||||
for (let n = 0; n < 20; n++) {
|
||||
w.poll();
|
||||
}
|
||||
check("a player without its ability system: no effect yet, quiet", w.player.active.length == 0 && !w.cleared);
|
||||
w.player.noAsc = false;
|
||||
w.player.base.Attack = 0;
|
||||
w.poll();
|
||||
check("an attribute not set up yet is left alone, the other one is not", w.player.active.length == 1
|
||||
&& w.player.active[0].attr == "ShachiAttack");
|
||||
w.player.base.Attack = 100;
|
||||
w.poll();
|
||||
check("... and gets its effect at a later poll", is(w, 150, 120, 0.5) && w.player.active.length == 3);
|
||||
w.player.clear();
|
||||
w.poll();
|
||||
check("effects the game cleared (death) come back once", is(w, 150, 120, 0.5) && w.player.active.length == 3);
|
||||
const old = w.player;
|
||||
old.free();
|
||||
for (let n = 0; n < 20; n++) {
|
||||
w.poll();
|
||||
}
|
||||
check("a freed player object: quiet", w.warnings.length == 0 && !w.cleared);
|
||||
w.player = character("/Game/Map.Hun_1");
|
||||
w.poll();
|
||||
check("a new player with the same path name gets its effects", is(w, 150, 120, 0.5) && w.player.active.length == 3);
|
||||
w.player.clear();
|
||||
w.player = character("/Game/Map.Hun_1");
|
||||
w.poll();
|
||||
check("... also while the old object is still there", is(w, 150, 120, 0.5) && w.player.active.length == 3);
|
||||
check("the effect assets are not loaded again", w.loaded.length == 3);
|
||||
const first = w.player;
|
||||
w.player = character("/Game/Map.Other_2");
|
||||
w.poll();
|
||||
w.player = first;
|
||||
w.poll();
|
||||
check("back to a first character: still one effect each", is(w, 150, 120, 0.5) && first.active.length == 3);
|
||||
w.stop();
|
||||
check("stop() takes the effects off every character", first.active.length == 0);
|
||||
}
|
||||
|
||||
// The game refuses, a base value moves, errors.
|
||||
{
|
||||
const w = boot();
|
||||
w.player.refuse = true;
|
||||
w.poll();
|
||||
check("a refused effect: no line, no warning", w.logs.length == 1 && w.warnings.length == 0);
|
||||
w.player.refuse = false;
|
||||
w.poll();
|
||||
check("... and it is tried again", is(w, 150, 120));
|
||||
w.player.base.Attack = 130; // a level up
|
||||
w.poll();
|
||||
check("a new base value keeps the one effect", near(w.player.value("Attack"), 195) && w.player.active.length == 3);
|
||||
|
||||
const i = boot();
|
||||
i.player.instant = true;
|
||||
i.poll();
|
||||
check("an effect that lands on the base value: the base put back, the mod stops at once", i.player.base.Attack == 100
|
||||
&& i.cleared && i.warnings.length == 1 && i.warnings[0].includes("base value"));
|
||||
check("... before the other attribute is touched", i.player.base.ShachiAttack == 80);
|
||||
|
||||
const t = boot();
|
||||
t.poll();
|
||||
t.throws = true;
|
||||
for (let n = 0; n < 9; n++) {
|
||||
t.poll();
|
||||
}
|
||||
check("9 polls that throw: still running, quiet", !t.cleared && t.warnings.length == 0);
|
||||
t.throws = false;
|
||||
t.poll();
|
||||
t.throws = true;
|
||||
for (let n = 0; n < 9; n++) {
|
||||
t.poll();
|
||||
}
|
||||
check("a good poll starts the count again", !t.cleared);
|
||||
t.poll();
|
||||
check("10 in a row: stopped with one warning, the effects off", t.cleared && t.warnings.length == 1
|
||||
&& t.warnings[0].includes("stopped") && t.player.active.length == 0);
|
||||
|
||||
const g = boot({ noEffects: true });
|
||||
for (let n = 0; n < 10; n++) {
|
||||
g.poll();
|
||||
}
|
||||
check("the effect assets are gone (a game update): stopped, nothing changed", g.cleared && is(g, 100, 80)
|
||||
&& g.warnings[0].includes("GE_MA_Attack_0_Mul is missing"));
|
||||
|
||||
const k = boot({ settings: text(1.5, 1.5) });
|
||||
k.poll();
|
||||
k.player.stuck = true;
|
||||
setText(k, text(3, 3));
|
||||
check("an effect that cannot be taken off: never a second one on top", k.player.active.length == 2 && is(k, 150, 120));
|
||||
k.player.stuck = false;
|
||||
k.poll();
|
||||
check("... and it is replaced at a later poll", is(k, 300, 240) && k.player.active.length == 2);
|
||||
k.player.keeps = true;
|
||||
setText(k, text(2, 2));
|
||||
check("an effect the game keeps: never a second one on top", k.player.active.length == 2 && is(k, 300, 240));
|
||||
k.player.keeps = false;
|
||||
k.player.stuck = true;
|
||||
k.stop();
|
||||
check("stop() with an error: a warning, no throw", k.warnings.length == 1 && k.warnings[0].includes("stop:"));
|
||||
const e = boot({ settings: text(2, 2) });
|
||||
e.poll();
|
||||
e.player.stuck = true;
|
||||
setText(e, text(2, 2, "Off"));
|
||||
e.player.stuck = false;
|
||||
e.poll();
|
||||
check("Enable=Off is tried again after an error", e.player.active.length == 0);
|
||||
|
||||
const l = boot();
|
||||
for (let n = 0; n < 60; n++) {
|
||||
l.poll();
|
||||
l.player.clear();
|
||||
}
|
||||
check("at most 30 lines about effects", l.logs.length == 31);
|
||||
}
|
||||
|
||||
// The reload (Alt+F5) and the Mods Menu page.
|
||||
{
|
||||
const w = boot({ settings: text(2, 2) });
|
||||
w.poll();
|
||||
w.stop();
|
||||
check("stop() takes both effects off", is(w, 100, 80));
|
||||
const next = boot({ settings: text(2, 2), player: w.player });
|
||||
next.poll();
|
||||
check("the next copy gives x2, not x4", is(next, 200, 160));
|
||||
|
||||
const m = boot({ menu: true, settings: text(2, 2), settingsPath: MENU_PATH });
|
||||
m.poll();
|
||||
check("with Mods Menu: the page's file counts", is(m, 200, 160));
|
||||
m.files.set(MENU_PATH, text(5, 5));
|
||||
m.pushed[0].onChange();
|
||||
m.poll(100);
|
||||
check("a change on the page is used at the next poll", is(m, 500, 400));
|
||||
const shipped = fs.readFileSync(SETTINGS, "utf8");
|
||||
check("the page's rows are the file's keys with the same defaults", m.pushed[0].settings.every((row) =>
|
||||
shipped.includes(`\r\n${row.key}=${row.default === true ? "On" : row.default}\r\n`))
|
||||
&& m.pushed[0].settings.length == shipped.split("\r\n").filter((line) => /^\w+=/.test(line)).length);
|
||||
check("the page's number rows have the range 0.1 to 10", m.pushed[0].settings.filter((row) => row.type == "number")
|
||||
.every((row) => row.min === 0.1 && row.max === 10));
|
||||
}
|
||||
|
||||
// stop() and a failed start.
|
||||
{
|
||||
const w = boot();
|
||||
w.poll();
|
||||
w.stop();
|
||||
check("stop(): the poll timer cleared, a line for loader.log, no warning", w.cleared && w.warnings.length == 0
|
||||
&& w.logs[w.logs.length - 1].endsWith("] stopped"));
|
||||
const again = boot();
|
||||
check("a second start after stop() (the reload) loads", !again.loadError);
|
||||
const n = boot({ noGameInstance: true });
|
||||
check("no GameInstance: the load throws (PBZModLoader logs the mod as failed), one line, no timer",
|
||||
!!n.loadError && n.timer === undefined && n.warnings.length == 1 && n.warnings[0].includes("not started"));
|
||||
}
|
||||
|
||||
process.exit(failed ? 1 : 0);
|
||||
Reference in new issue
Block a user