Terraria ModLoader  0.11.5
A framework for Terraria mods
Terraria.ModLoader.Config.ModConfig Class Reference

ModConfig provides a way for mods to be configurable. ModConfigs can either be Client specific or Server specific. When joining a MP server, Client configs are kept but Server configs are synced from the server. Using serialization attributes such as [DefaultValue(5)] or [JsonIgnore] are critical for proper usage of ModConfig. tModLoader also provides its own attributes such as ReloadRequiredAttribute and LabelAttribute. More...

Public Member Functions

virtual bool AcceptClientChanges (ModConfig pendingConfig, int whoAmI, ref string message)
 Called on the Server for ServerSide configs to determine if the changes asked for by the Client will be accepted. Useful for enforcing permissions. Called after a check for NeedsReload. More...
 
virtual bool Autoload (ref string name)
 
virtual ModConfig Clone ()
 tModLoader will call Clone on ModConfig to facilitate proper implementation of the ModConfig user interface and detecting when a reload is required. Modders need to override this method if their config contains reference types. Failure to do so will lead to bugs. See ModConfigShowcaseDataTypes.Clone for examples and explanations. More...
 
virtual bool NeedsReload (ModConfig pendingConfig)
 Whether or not a reload is required. The default implementation compares properties and fields annotated with the ReloadRequiredAttribute. Unlike the other ModConfig hooks, this method is called on a clone of the ModConfig that was saved during mod loading. The pendingConfig has values that are about to take effect. Neither of these instances necessarily match the instance used in OnLoaded. More...
 
virtual void OnChanged ()
 This hook is called anytime new config values have been set and are ready to take effect. This will always be called right after OnLoaded and anytime new configuration values are ready to be used. The hook won't be called with values that violate NeedsReload. Use this hook to integrate with other code in your Mod to apply the effects of the configuration values. If your NeedsReload is correctly implemented, you should be able to apply the settings without error in this hook. Be aware that this hook can be called in-game and in the main menu, as well as in single player and multiplayer situations. More...
 
virtual void OnLoaded ()
 This method is called when the ModConfig has been loaded for the first time. This happens before regular Autoloading and Mod.Load. You can use this hook to assign a static reference to this instance for easy access. tModLoader will automatically assign (and later unload) this instance to a static field named Instance in the class prior to calling this method, if it exists. More...
 

Properties

Mod mod [get, set]
 
abstract ConfigScope Mode [get]
 
string Name [get, set]
 

Detailed Description

ModConfig provides a way for mods to be configurable. ModConfigs can either be Client specific or Server specific. When joining a MP server, Client configs are kept but Server configs are synced from the server. Using serialization attributes such as [DefaultValue(5)] or [JsonIgnore] are critical for proper usage of ModConfig. tModLoader also provides its own attributes such as ReloadRequiredAttribute and LabelAttribute.

Definition at line 18 of file ModConfig.cs.

Member Function Documentation

virtual bool Terraria.ModLoader.Config.ModConfig.AcceptClientChanges ( ModConfig  pendingConfig,
int  whoAmI,
ref string  message 
)
virtual

Called on the Server for ServerSide configs to determine if the changes asked for by the Client will be accepted. Useful for enforcing permissions. Called after a check for NeedsReload.

Parameters
pendingConfigAn instance of the ModConfig with the attempted changes
whoAmIThe client whoAmI
messageA message that will be returned to the client, set this to the reason the server rejects the changes.
Returns
Return false to reject client changes

Definition at line 54 of file ModConfig.cs.

55  {
56  return true;
57  }
virtual bool Terraria.ModLoader.Config.ModConfig.Autoload ( ref string  name)
virtual
virtual ModConfig Terraria.ModLoader.Config.ModConfig.Clone ( )
virtual

tModLoader will call Clone on ModConfig to facilitate proper implementation of the ModConfig user interface and detecting when a reload is required. Modders need to override this method if their config contains reference types. Failure to do so will lead to bugs. See ModConfigShowcaseDataTypes.Clone for examples and explanations.

Returns

Referenced by Terraria.ModLoader.Config.ConfigManager.GeneratePopulatedClone().

+ Here is the caller graph for this function:

virtual bool Terraria.ModLoader.Config.ModConfig.NeedsReload ( ModConfig  pendingConfig)
virtual

Whether or not a reload is required. The default implementation compares properties and fields annotated with the ReloadRequiredAttribute. Unlike the other ModConfig hooks, this method is called on a clone of the ModConfig that was saved during mod loading. The pendingConfig has values that are about to take effect. Neither of these instances necessarily match the instance used in OnLoaded.

Parameters
pendingConfigThe other instance of ModConfig to compare against, it contains the values that are pending to take effect
Returns

Definition at line 71 of file ModConfig.cs.

References Terraria.ModLoader.Config.ConfigManager.GetFieldsAndProperties(), and Terraria.ModLoader.Config.ConfigManager.ObjectEquals().

72  {
73  foreach (PropertyFieldWrapper variable in ConfigManager.GetFieldsAndProperties(this))
74  {
75  ReloadRequiredAttribute reloadRequired = ConfigManager.GetCustomAttribute<ReloadRequiredAttribute>(variable, this, null);
76  if (reloadRequired != null)
77  {
78  // Do we need to implement nested ReloadRequired? Right now only top level fields will trigger it.
79  if (!ConfigManager.ObjectEquals(variable.GetValue(this), variable.GetValue(pendingConfig))) {
80  return true;
81  }
82  }
83  }
84  return false;
85  }

+ Here is the call graph for this function:

virtual void Terraria.ModLoader.Config.ModConfig.OnChanged ( )
virtual

This hook is called anytime new config values have been set and are ready to take effect. This will always be called right after OnLoaded and anytime new configuration values are ready to be used. The hook won't be called with values that violate NeedsReload. Use this hook to integrate with other code in your Mod to apply the effects of the configuration values. If your NeedsReload is correctly implemented, you should be able to apply the settings without error in this hook. Be aware that this hook can be called in-game and in the main menu, as well as in single player and multiplayer situations.

Definition at line 43 of file ModConfig.cs.

Referenced by Terraria.ModLoader.ModNet.SendServerConfigs().

44  {
45  }

+ Here is the caller graph for this function:

virtual void Terraria.ModLoader.Config.ModConfig.OnLoaded ( )
virtual

This method is called when the ModConfig has been loaded for the first time. This happens before regular Autoloading and Mod.Load. You can use this hook to assign a static reference to this instance for easy access. tModLoader will automatically assign (and later unload) this instance to a static field named Instance in the class prior to calling this method, if it exists.

Definition at line 36 of file ModConfig.cs.

37  {
38  }

Property Documentation

Mod Terraria.ModLoader.Config.ModConfig.mod
getset

Definition at line 21 of file ModConfig.cs.

Referenced by Terraria.ModLoader.Mod.AddConfig().

abstract ConfigScope Terraria.ModLoader.Config.ModConfig.Mode
get

Definition at line 27 of file ModConfig.cs.

string Terraria.ModLoader.Config.ModConfig.Name
getset

Definition at line 24 of file ModConfig.cs.

Referenced by Terraria.ModLoader.Mod.AddConfig().