ModAnalyzer - Trivaxy/Libvaxy GitHub Wiki

ModAnalyzer

ModAnalyzer is a class Libvaxy provides as a wrapper around Mod, and it allows you to easily extract any tModLoader-supported content type from any mod in question.

Using ModAnalyzer is very simple. First, create a ModAnalyzer object wrapping around any Mod object of your choice. Let's imagine we want to get every single ModProjectile Thorium has. This is how you would do it:

Mod thorium = ModLoader.GetMod("ThoriumMod");

if (thorium == null)
    return; // remember, we cannot analyze a mod that isn't loaded!

ModAnalyzer analyzer = new ModAnalyzer(thorium); // create a ModAnalyzer wrapper around thorium

ModProjectile[] thoriumProjectiles = analyzer.GetResource<ModProjectile>(); // get all thorium ModProjectiles

Done! You used ModAnalyzer to grab all ModProjectiles from thorium. You can grab any tModLoader resource type using GetResource<T>, where T is a resource type.

If, for whatever reason, you need to grab every single resource a mod adds, ModAnalyzer provides a GetAllResources method which returns a Dictionary containing all the resources. The key is the type of the resource and the value is the GetResource<T> equivalent.

For example:

ModAnalyzer analyzer = new ModAnalyzer(someMod);
Dictionary<Type, object> resources = analyzer.GetAllResources();

foreach (ModWall wall in resources[typeof(ModWall)] as ModWall[])
    // do stuff with walls!

This is the list of resource types ModAnalyzer allows you to retrieve:

Resource Types
Texture2D
SoundEffect
Music
DynamicSpriteFont
Effect
ModItem
GlobalItem
EquipTexture
ModPrefix
ModDust
ModTile
GlobalTile
ModTileEntity
ModWall
GlobalWall
ModProjectile
GlobalProjectile
ModNPC
GlobalNPC
ModPlayer
ModMountData
ModBuff
GlobalBuff
ModWorld
ModUgBgStyle
ModSurfaceBgStyle
GlobalBgStyle
ModWaterStyle
ModWaterfallStyle
ModRecipe
GlobalRecipe
ModTranslation
ModGore