forked from pipliz/ColonySurvival
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_callbacks.txt
437 lines (374 loc) · 20.7 KB
/
mod_callbacks.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
These callbacks are called in order of placement here:
void OnAssemblyLoaded (string p)
Called directly upon discovering a method with this attribute; passes the assemblies path as a parameter. Can't use providesfor/dependson here.
Builtin callback uses:
pipliz.blocknpcs.assemblyload
Calculates the blocknpc mod gamedata directory path
pipliz.colonyserverwrapper.load
Checks the commandline arguments for "+logto {port}", and if found, tries to connect to said port via tcp
void AfterModsLoaded (List<ModLoader.ModAssembly> list)
Called after all mods are loaded, list is the list of loaded assemblies. Useful for using reflection to link up things
Builtin callback uses:
pipliz.apiprovider.parsemods
Parses loaded assemblies looking for [AutoLoadedResearchable] classes, adds these to the Pipliz.APIProvider.Science.ResearchableManager.
void AfterStartup ()
Basically at the end of AfterModsLoaded. Possibly deprecated soon.
Builtin callback uses:
pipliz.server.ai.aimanager.startthread
Starts AI precalculation thread
void AfterSelectedWorld ()
First callback after the world to load has been determined.
pipliz.server.applytexturemappingpatches
ProvidesFor pipliz.server.registertexturemappingtextures
Applies texture mapping changes applied through modInfo.json jsonFiles or ItemTypesServer.QueueTextureMapping methods
pipliz.server.registertexturemappingtextures
Actually starts loading the texture files into the filetable
So removing/changing texture mappings (ItemTypesServer.TextureMappings) should be done before this
pipliz.server.registernpctextures
Registers the hardcoded npc texture paths to load into the FileTable cache
pipliz.server.registerwatertextures
Registers the hardcoded water texture paths to load into the FileTable cache
pipliz.server.registeraudiofiles
Loads the gamedata/audio/audioFiles.json file.
To add custom audio description json's: Make a callback inbetween registeraudiofiles and loadaudiofiles, where you add the jsonnode to the array jsonnode to ItemTypesServer.AudioFilesJSON
pipliz.server.loadaudiofiles
DependsOn pipliz.server.registeraudiofiles
Registers the .ogg's from ItemTypesServer.AudioFilesJSON and creates the byte[] package to send to users
pipliz.server.localization.startload
Starts loading the json files from disk
void AddItemTypes (Dictionairy<string, ItemTypesServer.ItemTypeRaw> dict)
Allows altering {dict}, to add/remove types. Called before AfterAddingBaseTypes
pipliz.server.applymoditempatches
applies types.json patches loaded through the modinfo.json jsonFiles or ItemTypesServer.QueueItemType methods
void AfterAddingBaseTypes (Dictionairy<string, ItemTypesServer.ItemTypeRaw> dict)
Allows altering {dict}, to add/remove types. Called after AddItemTypes
pipliz.blocknpcs.addlittypes
Adds the lit rotatable types like furnace/oven/bloomery/fineryforge/kiln through code.
They're not in types.json due to the length and repetitiveness of the child types (2x4 + 2, 2 parent types + 2 for lit/unlit * 4 for rotations)
void AfterItemTypesDefined ()
Do things that require all itemtypes to be defined here. Loading recipes etc.
Builtin callback uses:
pipliz.server.registercallbacks
Registers base game ItemTypesServer callbacks
pipliz.server.terraingenerator.setdefault
Sets the default terrain generator
pipliz.server.blackandwhitelistingreload
Loads the whitelist & blacklist files
pipliz.server.loadpermissions
Loads the permissions files
pipliz.server.loadtimecycle
Loads the time into the timecycle class
pipliz.server.loadupdatableblocks
Loads the various updatable blocks (wheat, saplings, flax)
pipliz.server.loadwater
Loads the tracked water blocks (for updates)
pipliz.blocknpcs.registerjobs
[ProvidesFor("pipliz.apiprovider.jobs.resolvetypes")] -> registers jobs to the apiprovider to resolve
Registers npc recipes to the APIPRovider RecipeManager
pipliz.server.loadnpctypes
[ProvidesFor("pipliz.server.loadnpcs")] -> npc's need the npc types
Loads NPCTypes from "gamedata/npctypes.json"
pipliz.server.registermonstertextures
[DependsOn("pipliz.server.loadnpctypes")]
Queues up the monster textures from npc settings to load in the filetable
pipliz.apiprovider.jobs.resolvetypes
[DependsOn("pipliz.server.loadnpctypes")] -> Wait for base game to add npc types first, to allow overriding
[ProvidesFor("pipliz.server.loadresearchables")] -> Registers NPC types (which may be used in researchables? not sure :') )
Inserts the registered jobs' npctypes into the game
pipliz.server.recipeplayerload
[ProvidesFor("pipliz.server.loadresearchables")] -> researchables may try unlocking these recipes
Applies player recipe patches loaded from modinfo.json jsonFiles or RecipePlayer.QueuePlayerRecipes methods
pipliz.server.recipenpcload
[ProvidesFor("pipliz.server.loadresearchables")] -> researchables may try unlocking these recipes
Applies npc recipe patches loaded from modinfo.json jsonFiles or RecipeStorage.QueueNPCRecipes methods
pipliz.server.loadresearchables
[ProvidesFor("pipliz.server.loadplayers")] -> as player savegames contain research progress (which references researchables)
Loads the researchables
pipliz.server.loadplayers
Loads the player save files (stockpile, inventory, position)
pipliz.server.loadbanners
[DependsOn("pipliz.server.loadplayers")] -> banners store per player
Loads banners
pipliz.server.loadnpcs
[DependsOn("pipliz.server.loadbanners")] -> laborers are stored per banner
Loads the saved npc's
pipliz.server.loadberryareajobs
pipliz.server.loadwheatfarmerareajobs
pipliz.server.loadflaxfarmerareajobs
pipliz.server.loadforesterareajobs
pipliz.server.loadminerareajobs
pipliz.server.loadbedblocks
pipliz.server.loadstockpileblocks
For all of these:
[DependsOn("pipliz.server.loadnpcs")] -> they deal with npc's or need banners/players loaded
Load various tracked blocks
void OnAddResearchables ()
Place to add researchables to Server.Science.ScienceManager
Builtin callback uses:
pipliz.apiprovider.registerresearchables
Registers the researchables from Pipliz.APIProvider.Science.ResearchableManager to the Server.Science.ScienceManager.
void AfterWorldLoad ()
After all misc data is loaded (structures, npc's, player data, lots)
Builtin callback uses:
pipliz.apiprovider.jobs.registercallbacks
Registers the OnAdd/OnRemove callbacks from the blockjobs added through BlockJobManagerTracker.Register
pipliz.apiprovider.jobs.load
Loads the registered blockjobs from the savegame, if any exist
pipliz.server.monsterspawner.register
Registers the default monster spawner to MonsterTracker.MonsterSpawner
pipliz.server.monsterspawner.fetchnpctypes
Fetches the zombie types (aa -> cc)
pipliz.server.ai.aimanager.defaultpathfinder
Sets the Server.AI.AIManager.PathFinder instances to the DefaultPathFinder.
pipliz.server.localization.waitforloading
Waits to ensure the files in Server.Localization.LoadedTranslation are fully loaded
pipliz.server.localization.convert
DependsOn pipliz.server.localization.waitforloading
Converts the json nodes into byte[] packages for networking.
To add/change/remove localization, edit the desired JSONNode in Server.Localization.Localization.LoadedTranslation in a callback that has the following attributes:
[ModLoader.ModCallbackDependsOn("pipliz.server.localization.waitforloading")]
[ModLoader.ModCallbackProvidesFor("pipliz.server.localization.convert")]
void AfterNetworkSetup ()
After the NetworkWrapper class is loaded, ready to send data. Can take a few seconds for steam servers - it's after port forwarding etc is done on another thread.
These callbacks are done at various times:
void OnUpdateStart ()
Start of Unity's Update loop, before anything is called (except for quitting mechanisms).
void OnUpdate ()
Just after OnUpdateStart, after the ThreadManager did main thread delegates. Probably the place to put the bulk of per-frame-updates.
Builtin callback uses:
pipliz.server.senddirtyscience
Sends updates from changed science managers to their owners on an interval
pipliz.colonyserverwrapper.process
If +logto was specified as launch argument, this will receive the input from said port
void OnUpdateEnd ()
Just before the end of the update loop, after OnUpdate (after all relevant gamecode)
void OnGUI ()
Unity's legacy GUI loop - use UnityEngine.GUI calls here to implement some basic interface things (on the server)
void FixedUpdate ()
Unity's FixedUpdate loop
void LateUpdate ()
Unity's LateUpdate loop (comes after Update and some unity internal things)
void OnApplicationFocus (bool b)
Unity's OnApplicationFocus method.
void OnApplicationPause (bool b)
Unity's OnApplicationPause method (probably unused, as the game does not have proper support for pausing, but hey here is an entry)
void OnPlayerConnectedEarly (Player p)
Player {p} connected to the server. Very early call, player will probably ignore most messages here.
Builtin callback uses:
pipliz.server.resetsciencedeltaupdates
Resets ScienceManagerPlayer to send initial progress again
void OnPlayerConnectedLate (Player p)
Player {p} connected to the server. Messages sent here will be received after the client is done loading. Allows for chat messages.
Builtin callback uses:
pipliz.server.queueinitialsend
Queues a send to the player, to set initial science state
pipliz.server.sendnpctypes
Sends the npctypes packet
pipliz.server.sendaudiomapping
Sends the audio description json (ItemTypes.AudioFilesJSON)
pipliz.server.meshedobjects.sendtable
Sends the meshed objects table
pipliz.server.terraingenerator.startsendingbiomedata
Starts sending biome data to the player (for ambient audio mainly)
Calls ITerrainGenerator.StartSendingBiomeData on the active terrain generator.
pipliz.server.sendsetflight
Sends whether or not /setflight true was active
pipliz.mods.basegame.sendconstructiondata
Sends builder & digger limits
void OnPlayerDisconnected (Player p)
Player {p} was disconnected.
void OnPlayerMoved (Player p)
Player {p} sent an updated position. Called approx 6 times per second per player. New position/rotation is set in {p}.
Builtin uses:
pipliz.server.loadsurroundings
Queues chunks to ChunkQueue for loading the players' surroundings
void OnTryChangeBlock (ModLoader.OnTryChangeBlockData d)
Callback triggered by ServerManager.TryChangeBlock. {d} has the following fields:
{d.RequestedByPlayer} - the player (in)directly calling TryChangeBlock. Can be null for code originating calls.
{d.Position} - the position where the change is desired
{d.TypeOld} - block type at {d.Position} before any change
{d.TypeNew} - block type desired at {d.Position} - BuiltinBlocks.Air for block removal. Can be changed.
{d.CallbackState} - enum to communicate the effect of this callback. Can be changed.
| Default - callback doesn't require altered handling of TryChangeBlock
- Will call World.TrySetTypeAt, ItemTypesServer.OnChange, send audio if callback origin is server & the flag is set and lastly it'll send the block change to players
| CallbackConsumed - TryChangeBlock won't do anything more, and return {d.CallbackConsumedResult}
| Cancelled - TryChangeBlock won't do anything more, and return false. (use for anti-grief etc)
{d.CallbackOrigin} - enum to indicate what triggered TryChangeBlock
| ClientPlayerManual - player digging
| ClientScript - player through tools ('special block removal', command tool placing jobs)
| Server - caused by server code
{d.InventoryItemResults} - inventory results for the player, if the CallbackOrigin == ClientPlayerManual. Can be changed (don't null or store it though)
{d.CallbackConsumedResult} - return value of TryChangeBlock when CallbackState is set to CallbackConsumed. Can be changed.
{d.PlayerClickedData} - only set if callback origin is from the client. Same data as in the "OnPlayerClicked" callback.
void OnLoadingPlayer (JSONNode n, Player p)
Player {p} was loaded with json file {n}.
Builtin callback uses:
pipliz.server.loadplayerscience
Loads any science progress from the jsonnode
pipliz.server.loadplayerlimits
Loads any player limits from the jsonnode
pipliz.server.loadsetflight
Loads whether or not /setflight true is active
void OnSavingPlayer (JSONNode n, Player p)
Player {p} is being saved into json file {n}.
Builtin callback uses:
pipliz.server.saveplayerscience
Saves any science progress from the player to it's file
pipliz.server.saveplayerlimits
Saves any player limits to it's file
pipliz.server.savesetflight
Saves whether or not /setflight true is active
void OnQuitEarly ()
Called upon quitting gracefully
General.Application.OnQuit @ -200, called before most other on quit actions
Builtin callback uses:
pipliz.shared.waitforasyncquitsearly
Waits for any async autosaving etc to complete before starting onquit events
void OnQuit ()
Called upon quitting gracefully
General.Application.OnQuit @ 0, after connected players are disconnected, various things saving at the same timepipliz.apiprovider.registerrecipes
Builtin callback uses:
pipliz.server.ai.aimanager.quitthread
Pokes the AI precalculation thread from sleeping so it can quit
pipliz.server.saveberryareajobs
pipliz.server.savewheatfarmerareajobs
pipliz.server.saveflaxfarmerareajobs
pipliz.server.saveforesterareajobs
pipliz.server.saveminerareajobs
pipliz.server.savebanners
pipliz.server.savebedblocks
pipliz.server.savestockpileblocks
Save various tracked blocks
pipliz.server.savenpc
Saves npc's
pipliz.server.savetimecycle
Saves time to WorldSettings
pipliz.server.saveupdatableblocks
Saves the updatable blocks (wheat, flax, saplings)
pipliz.server.savewater
Saves the updatable water blocks
void OnQuitLate ()
Called upon quitting gracefully
General.Application.OnQuit @ 100, after most quit actions happened
pipliz.server.saveworldsettings
Saves the servermanager.worldsettings
pipliz.shared.waitforasyncquits
Waits for the General.Application start async quits to complete.
pipliz.colonyserverwrapper.dispose
[DependsOn("pipliz.server.saveworldsettings")] - so that logs from there are also sent
[DependsOn("pipliz.shared.waitforasyncquits")] - ^
Closes the log streams if they were open
void OnResearchableCompleted (Server.Science.IResearchable res)
Called upon completion of a researchable
void OnPlayerDeath (Players.Player p)
Called upon the death of player p.
Builtin callback uses:
pipliz.server.onplayerdeath
Sets health to 0, sends audio, clears inventory, prints death to log
void OnPlayerRespawn (Players.Player p)
Called upon the respawning of player p (player clicked the button).
Builtin callback uses:
pipliz.server.onplayerrespawn
Teleports player to their base, sets health to starting health, prints respawn to log
void OnItemTypeRegistered (ItemTypes.ItemType type)
Called when a resolved type is registered to ItemTypes
Builtin callback uses:
pipliz.server.itemtypesserver
Parses server specific things of itemtypes:
Registers the parents of types for use with itemtype actions
Adds icons from types to the FileTable cache
Adds meshes from types to the FileTable cache
void OnMonsterDied (IMonster monster)
Called when a monster died
void OnMonsterHit (IMonster monster, ModLoader.OnHitData d)
{monster} - the monster instance that is being hit
{d.ResultDamage} - the resulting damage that will be applied to the {monster}
{d.HitDamage} - the damage amount being done
{d.HitSourceObject} & {d.HitSourceObjectType}
| type enum indicates what type of source is used
| None -> unknown, shouldn't really be used
| Misc -> mod use?
| PlayerProjectile -> hit by a players projectile, sourceObject is the Players.Player
| PlayerClick -> hit by a players melee, sourceObject is the Players.Player
| NPC -> hit by the npc's actions, sourceObject is the NPCBase
| Monster -> hit by a monster's actions, sourceObject is the IMonster
| FallDamage -> damage from falling. sourceObject is who caused the fall? :)
void OnMonsterSpawned (IMonster monster)
Called when a monster was spawned
void OnNPCLoaded (NPC.NPCBase npc, JSONNode node)
Loaded {npc} from {node}
void OnNPCSaved (NPC.NPCBase npc, JSONNode node)
Saved {npc} into {node} - can add custom values to the node
void OnNPCRecruited (NPC.NPCBase npc)
Recruited NPC {npc} - see npc.Colony for ownership
void OnNPCDied (NPC.NPCBase npc)
{npc} died - see npc.Colony for ownership
Builtin callback uses:
pipliz.server.refundrecruitement
If the npc had a job, refund the recruitment item to the stockpile
void OnNPCJobChanged (TupleStruct<NPC.NPCBase, IJob, IJob> data)
data.item1 -> {npc}
data.item2 -> {old job}
data.item3 -> {new job}
{npc} has changed job from {old job} to {new job}
Builtin callback uses:
pipliz.server.refundrecruitement
Add {old job} recruitment item to the stockpile
void OnNPCHit (NPC.NPCBase npc, ModLoader.OnHitData d)
See OnMonsterHit callback, they're pretty equivalent
void OnPlayerHit (Players.Player player, ModLoader.OnHitData d)
See OnMonsterHit callback, they're pretty equivalent
void OnPlayerClicked (Players.Player player, Pipliz.Box<Shared.PlayerClickedData> boxedData)
boxedData.item1 -> clickedData
{player} clicked, resulting in {clickedData}. Don't store the Box<>.
Check {clickedData.consumedType} if the click was already consumed by something
Check {clickedData.clickType} whether it's a left or right click
Check {clickedData.rayCastHit.rayHitType} for which data is valid.
If it's Block, distanceToHit, voxelHit, voxelSideHit and typeHit become valid
If it's NPC, distanceToHit and hitNPCID become valid
Builtin callback uses:
pipliz.server.players.hitnpc
Checks if the player hit an npc, if that's the case, cause damage to it
The following 'paragraph' callbacks are all called from the filesaver thread. Be careful with multithreading, a significant portion of the game is not threadsafe.
void OnSavedRegionToDisk ()
A region is saved to the disk. Also possibly called when quitting the game, and then it's called from a random thread pool thread (!!!)
void OnLoadedRegionFromDisk ()
A region is loaded from the disk.
void OnSavedChunkToRegion ()
A chunk is saved to the region. The chunk is locked for reading data.
void OnLoadedChunkFromRegion ()
A chunk is filled from a region in memory. The chunk is locked for writing data.
void OnAutoSaveWorld ()
Triggered every x seconds, to autosave non-block data (jobs, npc's, players)
Builtin callback uses:
A lot. Basically all callbacks from OnQuit to do with saving are in here as well (but then with auto in their identifier)
void OnPlayerRecipeSettingChanged (RecipeStorage.PlayerRecipeStorage storage, Recipe recipe, Box<RecipeSetting> recipeSetting)
Triggered every time a recipe limit is changed. Don't store the Box<> (it gets reused)
See storage.Player for the owner
This is also called upon loading the settings from JSON.
It's only calledif the setting is not (!) the default priority / limit of said recipe.
void OnNPCCraftedRecipe (IJob job, Recipe recipe, List<InventoryItem> results)
Triggered every time a npc crafts a recipe. Don't store the List<>, it's reused.
Results contains the recipe.Results by default, the List<> can be edited.
After the callback the results will be added to the block's inventory.
If the results list is not empty after the callback, the npc indicator will show a random type from the results.
void OnNPCGathered (IJob job, Vector3Int location, List<ItemTypes.ItemTypeDrops> results)
Triggered every time a npc gathers something at {location}. Don't store the List<>, it's reused.
Results contains the default gathered materials, can be edited.
After the callback the results will be added to the npc's inventory.
The location is the position where something happened, doesn't have to be the job position.
void OnShouldKeepChunkLoaded (ChunkUpdating.KeepChunkLoadedData data)
!!! can be called from multiple threads, be aware !!!
Periodically triggered for every chunk loaded. Use it to keep chunks loaded outside of the player / banner zones.
{data.CheckedChunk} - the chunk being checked
{data.MillisecondsTillNextCheck} - the time till the next check will be issued. Starts at Random between 24000 and 64000
{data.Result} - bool indicating whether or not to keep this chunk. Defaults to false.
Builtin callback uses:
pipliz.server.bannercheck
Sets result to true if any banner within Banner.LoadedRadius has colonists associated with it
If that's true, also multiplies time till next check by 5; assuming a colony doesn't disappear often.
pipliz.server.playercheck
if Result is false, checks whether there are connected players nearby. If so, sets result to true.
NPC temporary values - unused by server code
Monster temporary values - unused by server code
Player Temporary values: Variables stored in player.GetTempValues() dict (if set - defaults may not be in there)