This repository has been archived by the owner on Apr 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathClassicItems.cs
148 lines (120 loc) · 5.96 KB
/
ClassicItems.cs
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
using BepInEx;
using MonoMod.Cil;
using R2API;
using R2API.Utils;
using RoR2;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using BepInEx.Configuration;
using Mono.Cecil.Cil;
using System;
using TMPro;
using UnityEngine.Networking;
using Path = System.IO.Path;
using System.Collections.ObjectModel;
using TILER2;
using static TILER2.MiscUtil;
using System.Runtime.Serialization;
using System.Linq;
using RoR2.ExpansionManagement;
namespace ThinkInvisible.ClassicItems {
[BepInPlugin(ModGuid, ModName, ModVer)]
[BepInDependency(R2API.R2API.PluginGUID, R2API.R2API.PluginVersion)]
[BepInDependency(TILER2Plugin.ModGuid, TILER2Plugin.ModVer)]
[NetworkCompatibility(CompatibilityLevel.EveryoneMustHaveMod, VersionStrictness.EveryoneNeedSameModVersion)]
[R2APISubmoduleDependency(nameof(ItemAPI), nameof(LanguageAPI), nameof(PrefabAPI), nameof(LoadoutAPI), nameof(RecalculateStatsAPI))]
public class ClassicItemsPlugin:BaseUnityPlugin {
public const string ModVer = "7.1.0";
public const string ModName = "ClassicItems";
public const string ModGuid = "com.ThinkInvisible.ClassicItems";
internal static ConfigFile cfgFile;
internal static FilingDictionary<CatalogBoilerplate> masterItemList = new FilingDictionary<CatalogBoilerplate>();
public class GlobalConfig:AutoConfigContainer {
[AutoConfig("If true, disables the Rusty Jetpack gravity reduction while Photon Jetpack is active. If false, there shall be yeet.",
AutoConfigFlags.PreventNetMismatch)]
public bool coolYourJets {get; private set;} = true;
}
public static readonly GlobalConfig globalConfig = new GlobalConfig();
public static BuffDef freezeBuff {get;private set;}
public static BuffDef fearBuff {get;private set;}
internal static BepInEx.Logging.ManualLogSource _logger;
public static AssetBundle resources { get; private set; }
private void Awake() {
_logger = Logger;
Logger.LogDebug("Performing plugin setup:");
Logger.LogDebug("Loading assets...");
using(var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ClassicItems.classicitems_assets")) {
resources = AssetBundle.LoadFromStream(stream);
}
cfgFile = new ConfigFile(Path.Combine(Paths.ConfigPath, ModGuid + ".cfg"), true);
Logger.LogDebug("Loading global configs...");
globalConfig.BindAll(cfgFile, "ClassicItems", "Global");
Logger.LogDebug("Instantiating item classes...");
masterItemList = T2Module.InitAll<CatalogBoilerplate>(new T2Module.ModInfo {
displayName = "Classic Items",
longIdentifier = "ClassicItems",
shortIdentifier = "CI",
mainConfigFile = cfgFile
});
Logger.LogDebug("Loading item configs...");
foreach(CatalogBoilerplate x in masterItemList) {
x.SetupConfig();
}
Logger.LogDebug("Registering item attributes...");
foreach(CatalogBoilerplate x in masterItemList) {
x.SetupAttributes();
}
Logger.LogDebug("Registering shared buffs...");
//used only for purposes of Death Mark; applied by Permafrost and Snowglobe
freezeBuff = ScriptableObject.CreateInstance<BuffDef>();
freezeBuff.buffColor = Color.cyan;
freezeBuff.canStack = false;
freezeBuff.isDebuff = true;
freezeBuff.name = "CIFreeze";
freezeBuff.iconSprite = resources.LoadAsset<Sprite>("Assets/ClassicItems/Textures/ClassicIcons/permafrost_icon.png");
ContentAddition.AddBuffDef(freezeBuff);
fearBuff = ScriptableObject.CreateInstance<BuffDef>();
fearBuff.buffColor = Color.red;
fearBuff.canStack = false;
fearBuff.isDebuff = true;
fearBuff.name = "CIFear";
fearBuff.iconSprite = LegacyResourcesAPI.Load<Sprite>("textures/miscicons/texSprintIcon");
ContentAddition.AddBuffDef(fearBuff);
IL.EntityStates.AI.Walker.Combat.UpdateAI += IL_ESAIWalkerCombatUpdateAI;
Logger.LogDebug("Registering item behaviors...");
foreach(CatalogBoilerplate x in masterItemList) {
x.SetupBehavior();
}
Logger.LogDebug("Initial setup done!");
}
private void Start() {
Logger.LogDebug("Performing late setup:");
Logger.LogDebug("Late setup for individual items...");
T2Module.SetupAll_PluginStart(masterItemList);
Logger.LogDebug("Late setup done!");
}
private void IL_ESAIWalkerCombatUpdateAI(ILContext il) {
ILCursor c = new ILCursor(il);
int locMoveState = 0;
bool ILFound = c.TryGotoNext(
x=>x.MatchLdarg(0),
x=>x.MatchLdfld<EntityStates.AI.Walker.Combat>("dominantSkillDriver"),
x=>x.MatchLdfld<RoR2.CharacterAI.AISkillDriver>("movementType"),
x=>x.MatchStloc(out locMoveState))
&& c.TryGotoNext(MoveType.After,
x=>x.MatchCallOrCallvirt<EntityStates.AI.BaseAIState>("get_body"));
if(ILFound) {
c.Emit(OpCodes.Dup);
c.Emit(OpCodes.Ldloc_S, (byte)locMoveState);
c.EmitDelegate<Func<CharacterBody,RoR2.CharacterAI.AISkillDriver.MovementType,RoR2.CharacterAI.AISkillDriver.MovementType>>((body,origMove) => {
if(!body || !body.HasBuff(fearBuff)) return origMove;
else return RoR2.CharacterAI.AISkillDriver.MovementType.FleeMoveTarget;
});
c.Emit(OpCodes.Stloc_S, (byte)locMoveState);
} else {
Logger.LogError("Failed to apply shared buff IL patch (CIFear)");
}
}
}
}