Skip to content
DestroyedClone edited this page Apr 17, 2022 · 1 revision

Artifact Code Creation

(Taken from: https://github.com/risk-of-thunder/R2Wiki/wiki/Creating-Custom-Artifacts)

With R2API version 3.0.50, the ArtifactCodeAPI was added to the plethora of R2API Submodules.

ArtifactCodeAPI, in a nutshell, allows mod creators to add their own Artifact Codes to the game, so they can have them appear inside the bulwark's ambry and potentially unlock the artifact the same way as vanilla artifacts.

ArtifactCodeAPI Allows the mod creator to:

  • Create custom Artifact Codes easily with the ArtifactCode scriptable object.
  • Create new Artifact Compounds.

Custom Code

Custom Artifact Compound (Artifact Compound for Genetic Artifact, made by Rico.)

ArtifactCode scriptable object.

The ArtifactCode Scriptable Object greatly simplifies the creation of Codes, while normally you would make codes by using a Sha256HashAsset, and inputting complex ulong based values. ArtifactCode scriptable object creates these ulong values for you by reading thru the values inputted in 3 pairs of Vector3Int.

Here is an example on how the Artifact of Commando code would be generated using ArtifactCode

artifactCode = ScriptableObject.CreateInstance<ArtifactCode>();
artifactCode.topRow = new Vector3Int(CompoundValues.Square, CompoundValues.Square, CompoundValues.Square);
artifactCode.middleRow = new Vector3Int(CompoundValues.Square, CompoundValues.Square, CompoundValues.Square);
artifactCode.bottomRow = new Vector3Int(CompoundValues.Triangle, CompoundValues.Triangle, CompoundValues.Triangle);

Please note that each Vector3Int corresponds to a row in the Artifact tablet.

As well, keep in mind that AddCode() requires you to pass your ArtifactDef as an argument.

Thunderkit usage.

The ArtifactCode scriptable object can also be created from the editor and be used in conjunction with Thunderkit. It can be found in the Create Asset Menu

Implementing the code is as easy as grabbing the desired ArtifactDef & ArtifactCode from your assetBundle and registering the code.

var Def = Assets.LoadAsset<ArtifactDef>("ArtifactDef");
var Hash = Assets.LoadAsset<R2API.ArtifactCode>("Code");
R2API.ArtifactCodeAPI.AddCode(Def, Hash);

A list of the vanilla compound's Values can be found inside the ArtifactCodeAPI itself, under ArtifactCodeAPI.CompoundValues.

ArtifactCompound

Creating a custom artifact compound can be a good way to ensure nobody else uses the same code you just created, which allows modders to avoid having code conflicts alltogether. These are created using the ArtifactCompoundDef scriptable object, which is part of RoR2 code.

geneArtifactCompoundDef = ScriptableObject.CreateInstance<ArtifactCompoundDef>();
geneArtifactCompoundDef.modelPrefab = GeneticsArtifactPlugin.geneticAssetBundle.LoadAsset<GameObject>("Assets/Genetics/CompoundGene.prefab");
geneArtifactCompoundDef.value = 15;
ArtifactCodeAPI.AddCompound(geneArtifactCompoundDef);

Thunderkit usage.

Just like ArtifactCodes, you can easily create an ArtifactCompound using the Scriptable object and thunderkit's tools.

var Compound = Assets.LoadAsset<ArtifactCompoundDef>("CompoundDef");
R2API.ArtifactCodeAPI.AddCompound(Compound);