You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-3Lines changed: 52 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ This mod for [M&B2: Bannerlord](https://www.taleworlds.com/en/Games/Bannerlord)
4
4
5
5
## Prerequisites
6
6
7
-
The mod is tested with Bannerlord e1.5.7 and e1.5.8 beta. Older versions of the game *may* work, but are considered unsupported.
7
+
The mod is tested with Bannerlord e1.6.1 and e1.6.2 beta. Older versions of the game *may* work, but are considered unsupported.
8
8
9
9
There are no known compatibility issues with other Bannerlord mods.
10
10
@@ -203,6 +203,23 @@ void Test() {
203
203
```
204
204
Note that this object is shared by *all* scripts, and is also accessible via `csx.eval`.
205
205
206
+
### Accessing non-public members
207
+
208
+
Both `csx.eval` expressions and scripts are compiled with visibility checks disabled; thus, internal, protected, and private members can be accessed as well as public ones. Since CLR performs additional visibility checks at runtime, any expression that needs to ignore visibility needs to be wrapped with `IgnoreVisibility()` to disable those runtime checks. For example:
`StartRebellionEvent` is a private member of RebellionsCampaignBehavior; thus, `IgnoreVisibility` is required here.
216
+
217
+
The lambda passed to `IgnoreVisibility` is an expression tree, and all [limitations](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/conversions#anonymous-function-conversions) apply. In particular, the lambda cannot perform assignments. To allow private fields to be changed within the lambda, one has to use the `Set()` method instead:
Both `csx.eval` and scripts are executed in a pre-populated environment. It includes assembly references for all assemblies loaded in the Bannerlord process, and implicit `using` statements for all available namespaces that begin with `TaleWorlds`, as well as the following:
@@ -255,15 +272,20 @@ The following lookup tables are provided:
255
272
256
273
- `Kingdoms` for `Kingdom.All`
257
274
- `Clans` for `Clan.All`
258
-
- `Heroes` for `Hero.All`
275
+
- `Heroes` for `Hero.FindAll(_=>true)`
259
276
- `Nobles` for `Heroes[hero=>hero.IsNoble]`
260
277
- `Wanderers` for `Heroes[hero=>hero.IsWanderer]`
261
-
- `Settlements` for `Settlement.All`
278
+
- `Settlements` for `ObjectManager.GetObjectTypeList<Settlement>()`
262
279
- `Fiefs` for `Town.AllFiefs`
263
280
- `Towns` for `Town.AllTowns`
264
281
- `Castles` for `Town.AllCastles`
265
282
- `Villages` for `Village.All`
266
283
- `Parties` for `MobileParty.All`
284
+
- `ItemObjects` for `ObjectManager.GetObjectTypeList<ItemObject>()`
285
+
- `Perks` for `ObjectManager.GetObjectTypeList<PerkObject>()`
286
+
- `CharacterAttributes` for `ObjectManager.GetObjectTypeList<CharacterAttribute>()`
287
+
- `Traits` for `ObjectManager.GetObjectTypeList<TraitObject>()`
288
+
- `Skills` for `ObjectManager.GetObjectTypeList<SkillObject>()`
267
289
- `MyFiefs` for `MyClan.Fiefs`
268
290
- `MyTowns` for `MyFiefs[fief=>fief.IsTown]`
269
291
- `MyCastles` for `MyFiefs[fief=>fief.IsCastle]`
@@ -279,9 +301,11 @@ In addition to the usual C# implicit conversions, the mod also provides implicit
@@ -356,10 +380,35 @@ The mod comes with a stock `CampaignBehavior.csx` that already has the above sni
356
380
357
381
**WARNING**:messingaroundwith `CampaignBehavior.SyncData()` caneasilyrenderyoursavesunusable!Itisintentionallyundocumented; ifyoudon't already know what it is for, and how to *safely* use `IDataStore`, it'sbesttoleaveitalone.
358
382
383
+
### `SubModule`
384
+
385
+
Ifthere's a script named `SubModule`, it may define a method called `OnGameStart`:
Themodautomaticallygeneratesomnisharp.jsonintheuserscriptsfolder, whichenablesIntellisensein [VisualStudioCode](https://code.visualstudio.com/) (or any other editor or IDE that uses [OmniSharp](http://www.omnisharp.net/)). To use it, simply do File ⇒ Open Folder in VSCode to open the folder, and then open individual .csx files from the Explorer pane.
Scriptsarecompiledwithfulldebuginformation. IfVisualStudiois [attached](https://docs.microsoft.com/en-us/visualstudio/debugger/attach-to-running-processes-with-the-visual-studio-debugger) to the Bannerlord process, it is possible to set breakpoints, break on exceptions, and use all other debugging facilities.
0 commit comments