You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
453 lines
20 KiB
453 lines
20 KiB
using BepInEx; |
|
using BepInEx.Configuration; |
|
using HarmonyLib; |
|
using System; |
|
using UnityEngine; |
|
|
|
namespace UltimateBag |
|
{ |
|
[HarmonyPatch] |
|
[BepInPlugin(ID, NAME, VERSION)] |
|
public class UltimateBag : BaseUnityPlugin |
|
{ |
|
|
|
static public UltimateBag Instance { get; private set; } |
|
const string ID = "com.ness.UltimateBag"; |
|
const string NAME = "UltimateBag"; |
|
const string VERSION = "1.0"; |
|
|
|
|
|
internal void Awake() |
|
{ |
|
Instance = this; |
|
|
|
new Harmony("com.ness.UltimateBag").PatchAll(); |
|
|
|
Logger.LogMessage("UltimateBag is awake"); |
|
Update(); |
|
|
|
// CURRENT PREFAB |
|
UltimateBag.BagPrefabName = Config.Bind<string>("1.GENERAL", "Bag Visual", "5300120_PrimitiveSatchelBackpack_v", new ConfigDescription("Apply visual on the selected bag", new AcceptableValueList<string>( |
|
"5300000_AdventurerBackpack_v", |
|
"5300140_TraderFrameBackpack_v", |
|
"5300130_StrongBoxBackpack_v", |
|
"5300030_MasterTraderBackpack_v", |
|
"5300180_HornBackpack_v", |
|
"5300170_MageBackpack_v", |
|
"5380003_WeaverBackpack_v", |
|
"5300160_PreservationBackpack_v", |
|
"5300110_NomadBackpack_v", |
|
"5300041_ProspectorBackpackElite_v", |
|
"5300190_BoozuBackpack_v", |
|
"5300070_Wolfcase_v", |
|
"5300040_ProspectorBackpack_v", |
|
"5380002_ChalecedonyBackpack_v", |
|
"5380005_BrigandBackpack_v", |
|
"5300050_GlowstoneBackpack_v", |
|
"5380001_ChargedStoneBackpack_v", |
|
"5300120_PrimitiveSatchelBackpack_v"))); |
|
|
|
// SLOT 1 |
|
UltimateBag.EnableSlot1 = Config.Bind<bool>("2. WEAPON SLOT 1", "Enable Weapon Slot 1", true, "Add a weapon on your bag"); |
|
UltimateBag.VisualSlot1 = Config.Bind<int>("2. WEAPON SLOT 1", "Weapon ID", 2200000, "ItemID of the weapon you want to attach"); |
|
UltimateBag.PositionSlot1 = Config.Bind<string>("2. WEAPON SLOT 1", "Weapon Type", "Sword", new ConfigDescription("Choose the type of weapon select in Slot1. Required for positionning.", new AcceptableValueList<string>("Bow","Spear","Staff", "Axe(One Handed)", "Axe(Two Handed)", "Halberd", "Sword(One Handed)", "Sword(Two Handed)","Mace(One Handed)","Mace(Two Handed)"))); |
|
|
|
//SLOT 2 |
|
UltimateBag.EnableSlot2 = Config.Bind<bool>("3. WEAPON SLOT 2", "Enable Weapon Slot 2", true, "Add a weapon on your bag"); |
|
UltimateBag.VisualSlot2 = Config.Bind<int>("3. WEAPON SLOT 2", "Weapon ID", 2100999, "ItemID of the weapon you want to attach"); |
|
UltimateBag.PositionSlot2 = Config.Bind<string>("3. WEAPON SLOT 2", "Weapon Type", "Sword", new ConfigDescription("Choose the type of weapon select in Slot1. Required for positionning.", new AcceptableValueList<string>("Bow", "Spear", "Staff", "Axe(One Handed)", "Axe(Two Handed)", "Halberd", "Sword(One Handed)", "Sword(Two Handed)", "Mace(One Handed)", "Mace(Two Handed)"))); |
|
|
|
//SHIELD |
|
|
|
UltimateBag.EnableShield = Config.Bind<bool>("4. SHIELD", "Enable Shield", false, "Replace the backpack by a shield"); |
|
UltimateBag.ShieldVisual = Config.Bind<int>("4. SHIELD", "Shield ID", 2300050, "ItemID of the shield you want to attach"); |
|
|
|
//BOLT |
|
UltimateBag.AddBoltBool = Config.Bind<bool>("5.EFFECT", "Add Bolt Effect", true, "Add a bolt effect on your bag"); |
|
UltimateBag.BoltColor = Config.Bind<string>("5.EFFECT", "Color Bolt Effect", "yellow", new ConfigDescription("Choose color of bolt effect on your bag", new AcceptableValueList<string>("blue", "cyan", "gray", "green", "magenta", "red", "white", "yellow"))); |
|
|
|
//SPIRAL |
|
UltimateBag.AddSpiralBool = Config.Bind<bool>("6.EFFECT", "Add Spiral Effect", true, "Add a spiral effect on your bag"); |
|
UltimateBag.SpiralColor = Config.Bind<string>("6.EFFECT", "Color Spiral Effect", "yellow", new ConfigDescription("Choose color of spiral effect on your bag", new AcceptableValueList<string>("blue", "cyan", "gray", "green", "magenta", "red", "white", "yellow"))); |
|
|
|
//LANTERN |
|
UltimateBag.AddLanternBool = Config.Bind<bool>("7.LANTERN", "Add Lantern", true, "Add a bolt effect on your bag"); //BEPINEX CONFIGURATION MENU |
|
|
|
} |
|
|
|
void Update() { |
|
} //if (Input.GetKeyDown(KeyCode.N)) { //FOR TESTING BagSlot.Instance.Logger.LogMessage("KeyPress");}} // TESTING BLOCK |
|
|
|
static void ProcessVisualsExtend(Bag bag) |
|
{ |
|
|
|
if (bag.m_visualPrefabName == UltimateBag.BagPrefabName.Value) |
|
{ |
|
|
|
/* |
|
if (UltimateBag.BagPrefabName.Value == "5380005_BrigandBackpack_v") // DONE |
|
{ |
|
if (UltimateBag.AddLanternBool.Value) |
|
AddLanternSlot(bag, 0.0686f, 0.1271f, -0.2781f); //LanternSlot |
|
if (UltimateBag.AddBoltBool.Value) |
|
AddBolt(bag, 0f, 0.2f, 0f, UltimateBag.BoltColor.Value); // Bolt Effect |
|
if (UltimateBag.AddSpiralBool.Value) |
|
AddSpiral(bag, 0f, 0.2f, 0f, UltimateBag.SpiralColor.Value); // Spiral Effect |
|
if (UltimateBag.EnableSlot1.Value) |
|
AddWeaponSlot1(bag, VerifItemID(UltimateBag.VisualSlot1.Value, bow: true), -0.14f, 0.14f, 0f, 61.4246f, 141.3963f, 11.9091f); // Bow Attach |
|
//AddBow(bag, VerifItemID(UltimateBag.VisualSlot1.Value, bow: true), -0.14f, 0.14f, 0f, 61.4246f, 141.3963f, 11.9091f); |
|
if (UltimateBag.EnableSlot2.Value) |
|
AddWeaponSlot1(bag, VerifItemID(UltimateBag.VisualSlot2.Value, twoh: true), -0.28f, -0.035f, 0.48f, 2.734f, 64.5905f, 180.2475f); //2 Handed Sword Attach -0.28, -0.035, 0.48 |
|
} |
|
*/ |
|
|
|
// INITIALIZATION VARIABLE |
|
Vector3 positionSlot1 = new Vector3(-0.2101f, -0.0955f, -0.68f); |
|
Vector3 rotationSlot1 = new Vector3(1.0208f, 290.0177f, 179.9582f); |
|
Vector3 positionSlot2 = new Vector3(0.3f, -0.005f, -0.6f); |
|
Vector3 rotationSlot2 = new Vector3(357.5089f, 61.8f, 2.906f); |
|
string defineposandrot = UltimateBag.PositionSlot1.Value; |
|
string defineposandrot2 = UltimateBag.PositionSlot2.Value; |
|
|
|
// SWITCH FOR POSITION AND ROTATION |
|
switch (defineposandrot) //DONE |
|
{ |
|
case "Staff": |
|
positionSlot1 = new Vector3(-0.2101f, -0.0355f, -0.68f); |
|
rotationSlot1 = new Vector3(1.0208f, 290.0177f, 179.9582f); |
|
break; |
|
case "Bow": |
|
if (UltimateBag.BagPrefabName.Value == "5380005_BrigandBackpack_v") // SPECIAL PLACEMENT FOR BRIGANDBACKPACK |
|
{ |
|
positionSlot1 = new Vector3(-0.14f, 0.14f, 0f); |
|
rotationSlot1 = new Vector3(61.4246f, 141.3963f, 11.9091f); |
|
} else { |
|
positionSlot1 = new Vector3(0.04f, -0.04f, -0.14f); |
|
rotationSlot1 = new Vector3(356.3531f, 290.784f, 353.7287f); |
|
} |
|
break; |
|
case "Spear": |
|
positionSlot1 = new Vector3(-0.2901f, -0.0555f, -1f); |
|
rotationSlot1 = new Vector3(1.0208f, 290.0177f, 179.9582f); |
|
break; |
|
case "Axe(One Handed)": |
|
positionSlot1 = new Vector3(-0.02f, 0f, -0.4f); //-0.02, 0, -0.4 0.02f, -0.02f, -0.22f |
|
rotationSlot1 = new Vector3(5.2877f, 293.8563f, 175.003f); |
|
break; |
|
case "Axe(Two Handed)": |
|
positionSlot1 = new Vector3(0.22f, -0.095f, 0.24f); |
|
rotationSlot1 = new Vector3(2.8408f, 122.3997f, 188.2476f); |
|
break; |
|
case "Halberd": |
|
positionSlot1 = new Vector3(0.24f, -0.09f, 0.48f); |
|
rotationSlot1 = new Vector3(351.9301f, 292.5178f, 356.499f); |
|
break; |
|
case "Sword(One Handed)": |
|
positionSlot1 = new Vector3(-0.2413f, -0.031f, 0.2394f); //-0.02, 0, -0.4 0.02f, -0.02f, -0.22f |
|
rotationSlot1 = new Vector3(2.8648f, 59.127f, 179.9836f); |
|
break; |
|
case "Sword(Two Handed)": |
|
positionSlot1 = new Vector3(0.24f, -0.09f, 0.48f); |
|
rotationSlot1 = new Vector3(351.9301f, 292.5178f, 356.499f); |
|
break; |
|
case "Mace(One Handed)": |
|
positionSlot1 = new Vector3(-0.02f, 0f, -0.4f); //-0.02, 0, -0.4 0.02f, -0.02f, -0.22f |
|
rotationSlot1 = new Vector3(5.2877f, 293.8563f, 175.003f); |
|
break; |
|
case "Mace(Two Handed)": |
|
positionSlot1 = new Vector3(-0.2101f, -0.0355f, -0.68f); |
|
rotationSlot1 = new Vector3(1.0208f, 290.0177f, 179.9582f); |
|
break; |
|
default: |
|
break; |
|
} // POSITION AND ROTATION SLOT 1 |
|
|
|
switch (defineposandrot2) |
|
{ |
|
case "Staff": // DONE |
|
positionSlot2 = new Vector3(0.3f, -0.005f, -0.6f); |
|
rotationSlot2 = new Vector3(357.5089f, 61.8f, 2.906f); |
|
break; |
|
case "Bow": //DONE |
|
positionSlot2 = new Vector3(-0.04f, -0.04f, -0.12f); |
|
rotationSlot2 = new Vector3(2.734f, 64.5905f, 180.2475f); |
|
break; |
|
case "Spear": //DONE |
|
positionSlot2 = new Vector3(0.34f, -0.035f, -1.02f); |
|
rotationSlot2 = new Vector3(2.5851f, 250.0005f, 179.022f); |
|
break; |
|
case "Axe(One Handed)": |
|
positionSlot2 = new Vector3(0.1f, 0f, -0.4f); |
|
rotationSlot2 = new Vector3(358.5891f, 69.23f, 2.7964f); |
|
break; |
|
case "Axe(Two Handed)": |
|
positionSlot2 = new Vector3(-0.2f, 0.02f, 0.23f); |
|
rotationSlot2 = new Vector3(347.9792f, 231.782f, 6.1241f); |
|
break; |
|
case "Halberd": |
|
positionSlot2 = new Vector3(-0.26f, -0.07f, 0.51f); |
|
rotationSlot2 = new Vector3(8.9016f, 63.8621f, 181.4015f); |
|
break; |
|
case "Sword(One Handed)": |
|
positionSlot2 = new Vector3(0.28f, -0.08f, 0.24f); |
|
rotationSlot2 = new Vector3(359.7222f, 120.5592f, 184.8041f); |
|
break; |
|
case "Sword(Two Handed)": |
|
positionSlot2 = new Vector3(-0.28f, -0.035f, 0.48f); |
|
rotationSlot2 = new Vector3(2.734f, 64.5905f, 180.2475f); |
|
break; |
|
case "Mace(One Handed)": |
|
positionSlot2 = new Vector3(0.1f, 0f, -0.4f); |
|
rotationSlot2 = new Vector3(358.5891f, 69.23f, 2.7964f); |
|
break; |
|
case "Mace(Two Handed)": |
|
positionSlot2 = new Vector3(0.3f, -0.005f, -0.6f); |
|
rotationSlot2 = new Vector3(357.5089f, 61.8f, 2.906f); |
|
break; |
|
default: |
|
break; |
|
} // POSITION AND ROTATION SLOT 2 |
|
|
|
// POSITION AND ROTATION SHIELD |
|
Vector3 positionShield = new Vector3(0.0499f, 0.025f, -0.28f); |
|
Vector3 rotationShield = new Vector3(333.5798f, 282.9698f, 353.0449f); |
|
|
|
//PROCESS |
|
if (UltimateBag.AddBoltBool.Value) |
|
AddBolt(bag, 0f, 0.2f, 0f, UltimateBag.BoltColor.Value); // Bolt Effect |
|
if (UltimateBag.AddSpiralBool.Value) |
|
AddSpiral(bag, 0f, 0.2f, 0f, UltimateBag.SpiralColor.Value); // Spiral Effect |
|
if (UltimateBag.EnableSlot1.Value) |
|
AddWeaponSlot1(bag, VerifItemID(UltimateBag.VisualSlot1.Value, bow: true), positionSlot1, rotationSlot1); // Slot1 |
|
if (UltimateBag.EnableSlot2.Value) |
|
AddWeaponSlot2(bag, VerifItemID(UltimateBag.VisualSlot2.Value, twoh: true), positionSlot2, rotationSlot2); |
|
if (UltimateBag.AddLanternBool.Value || UltimateBag.BagPrefabName.Value == "5380005_BrigandBackpack_v") |
|
AddLanternSlot(bag, 0.0686f, 0.1271f, -0.2781f); //LanternSlot // PENSER A FAIRE UNE VALEUR POUR CHAQUE SAC SANS LANTERN |
|
if (UltimateBag.EnableShield.Value) |
|
AddShield(bag, VerifItemID(UltimateBag.ShieldVisual.Value), positionShield, rotationShield);// Slot2 |
|
|
|
|
|
//2300050 SHIELD WOLF |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void AddLanternSlot(Bag bag, float xPos, float yPos, float zPos) |
|
{ |
|
|
|
Bag adventurerBackpack = (Bag)ResourcesPrefabManager.ITEM_PREFABS["5300000"]; |
|
|
|
Transform lanternHolder = adventurerBackpack.LoadedVisual.transform.Find("LanternSlotAnchor"); // FIND LANTERN ANCHOR |
|
|
|
Transform cachedLanternAnchor = Instantiate(lanternHolder); // CLONE ANCHOR |
|
|
|
cachedLanternAnchor.parent = bag.LoadedVisual.transform; |
|
|
|
bag.m_lanternSlot = bag.GetComponentInChildren<BagSlotVisual>(); |
|
|
|
cachedLanternAnchor.localPosition = new Vector3(xPos, yPos, zPos); //0.0686f, 0.1271f, -0.2781f |
|
|
|
} |
|
|
|
/* |
|
static void AddWeaponSlot2(Bag bag, int itemID, float xPos, float yPos, float zPos, float xRot, float yRot, float zRot) |
|
{ |
|
Vector3 roteuler = new Vector3(xRot, yRot, zRot); |
|
|
|
GameObject clone2HW = Instantiate(GetVisuals(itemID)); // Clone |
|
|
|
clone2HW.transform.parent = bag.LoadedVisual.transform; |
|
|
|
clone2HW.transform.localPosition = new Vector3(xPos, yPos, zPos);// Position |
|
|
|
clone2HW.transform.localRotation = Quaternion.Euler(roteuler); //Rotation /!\ REQUIRE EULER/NORMALIZER VALUES |
|
|
|
clone2HW.transform.parent = bag.LoadedVisual.transform; // Attach |
|
} |
|
*/ |
|
|
|
|
|
|
|
static void AddWeaponSlot2(Bag bag, int itemID, Vector3 Pos, Vector3 Rot) |
|
{ |
|
Vector3 rot = Rot; // Assignation |
|
|
|
GameObject cloneSlot2 = Instantiate(GetVisuals(itemID)); // Clone |
|
|
|
cloneSlot2.transform.parent = bag.LoadedVisual.transform; // Attach |
|
|
|
cloneSlot2.transform.localPosition = Pos; // Position |
|
|
|
cloneSlot2.transform.localRotation = Quaternion.Euler(rot); // Rotation |
|
} |
|
|
|
static void AddWeaponSlot1(Bag bag, int itemID, Vector3 Pos, Vector3 Rot) |
|
{ |
|
Vector3 rot = Rot; // Assignation |
|
|
|
GameObject cloneSlot1 = Instantiate(GetVisuals(itemID)); // Clone |
|
|
|
cloneSlot1.transform.parent = bag.LoadedVisual.transform; // Attach |
|
|
|
cloneSlot1.transform.localPosition = Pos; // Position |
|
|
|
cloneSlot1.transform.localRotation = Quaternion.Euler(rot); //Rotation /!\ REQUIRE EULER/NORMALIZER VALUES |
|
|
|
|
|
} |
|
|
|
static void AddShield(Bag bag, int itemID, Vector3 Pos, Vector3 Rot) |
|
{ |
|
|
|
Vector3 rot = Rot; // Assignation |
|
|
|
GameObject shield = Instantiate(GetVisuals(itemID)); // Clone |
|
|
|
shield.transform.parent = bag.LoadedVisual.transform; // Attach |
|
|
|
shield.transform.localPosition = Pos; // Position |
|
|
|
shield.transform.localRotation = Quaternion.Euler(rot); // Rotation |
|
|
|
Transform model = bag.LoadedVisual.transform.Find("model"); |
|
|
|
model.gameObject.SetActive(false); |
|
|
|
} |
|
|
|
static void AddBolt(Bag bag, float x, float y, float z, string color = "yellow", bool hidelight = false) |
|
{ |
|
|
|
Bag mageBackpack = (Bag)ResourcesPrefabManager.ITEM_PREFABS["5300170"]; |
|
|
|
Transform bolt = mageBackpack.LoadedVisual.transform.Find("backpack").transform.Find("_boltCrackling_Example_FX"); |
|
|
|
Transform cachedBolt = Instantiate(bolt.transform); |
|
|
|
cachedBolt.parent = bag.LoadedVisual.transform; |
|
|
|
cachedBolt.localPosition = new Vector3(x, y, z); |
|
|
|
if (hidelight == true) |
|
|
|
{ |
|
cachedBolt.transform.GetComponentInChildren<Light>().intensity = 0; |
|
|
|
} |
|
|
|
Color colorchoice = ToColor(color); |
|
|
|
cachedBolt.transform.GetComponentInChildren<ParticleSystem>().startColor = colorchoice; |
|
|
|
cachedBolt.transform.GetComponentInChildren<Light>().color = colorchoice; |
|
|
|
cachedBolt.parent = bag.LoadedVisual.transform; |
|
} |
|
|
|
static void AddSpiral(Bag bag, float x, float y, float z, string color = "yellow") |
|
{ |
|
Bag glowBackpack = (Bag)ResourcesPrefabManager.ITEM_PREFABS["5300050"]; |
|
|
|
Transform spiral = glowBackpack.LoadedVisual.transform.Find("Particle System"); |
|
|
|
Transform cachedSpiral = Instantiate(spiral.transform); |
|
|
|
cachedSpiral.parent = bag.LoadedVisual.transform; |
|
|
|
cachedSpiral.localPosition = new Vector3(x, y, z); |
|
|
|
Color colorchoice = ToColor(color); |
|
|
|
cachedSpiral.transform.GetComponentInChildren<ParticleSystem>().startColor = colorchoice; |
|
|
|
cachedSpiral.parent = bag.LoadedVisual.transform; |
|
|
|
} |
|
|
|
|
|
//////////// UTILITY /////////////// |
|
|
|
public static int VerifItemID(int itemid, bool bag = false, bool bow = false, bool twoh = false) |
|
{ |
|
if (ResourcesPrefabManager.ITEM_PREFABS[itemid.ToString()].name != null) |
|
{ |
|
return itemid; |
|
} |
|
else |
|
{ |
|
if (bag == true) |
|
{ |
|
return 5300000; |
|
} |
|
else if (bow == true) |
|
{ |
|
return 2200000; |
|
} |
|
else if (twoh == true) |
|
{ |
|
return 2100999; |
|
} |
|
else return 5300000; |
|
|
|
} |
|
} |
|
|
|
public static Color ToColor(string color) |
|
{ |
|
return (Color)typeof(Color).GetProperty(color.ToLowerInvariant()).GetValue(null, null); |
|
} |
|
|
|
public static GameObject GetVisuals(int itemID) |
|
{ |
|
string visualsPath = ResourcesPrefabManager.ITEM_PREFABS[itemID.ToString()].m_visualPrefabPath; |
|
return ResourcesPrefabManager.Instance.m_itemVisualsBundle.LoadAsset<GameObject>(visualsPath + ".prefab"); |
|
} |
|
|
|
|
|
//////////// PATCH /////////////// |
|
|
|
[HarmonyPatch(typeof(Bag), "BaseInit"), HarmonyPrefix] |
|
static void Bag_BaseInit_Pre(Bag __instance) |
|
{ |
|
ProcessVisualsExtend(__instance); |
|
} |
|
|
|
//////////// CONFIG ///////////// |
|
|
|
public static ConfigEntry<string> PositionSlot1; |
|
public static ConfigEntry<string> PositionSlot2; |
|
public static ConfigEntry<bool> EnableSlot1; |
|
public static ConfigEntry<bool> EnableSlot2; |
|
public static ConfigEntry<bool> AddBoltBool; |
|
public static ConfigEntry<string> BoltColor; |
|
public static ConfigEntry<bool> AddSpiralBool; |
|
public static ConfigEntry<string> SpiralColor; |
|
public static ConfigEntry<bool> AddLanternBool; |
|
public static ConfigEntry<string> BagPrefabName; |
|
public static ConfigEntry<int> VisualSlot1; |
|
public static ConfigEntry<int> VisualSlot2; |
|
|
|
public static ConfigEntry<bool> EnableShield; |
|
public static ConfigEntry<int> ShieldVisual; |
|
|
|
public static AcceptableValueList<string> CurrentBag; |
|
|
|
public static ConfigEntry<bool> isStaffS1; |
|
public static ConfigEntry<bool> isStaffS2; |
|
public static ConfigEntry<bool> isSpearS1; |
|
public static ConfigEntry<bool> isSpearS2; |
|
public static ConfigEntry<bool> isBowS1; |
|
public static ConfigEntry<bool> isBowS2; |
|
public static ConfigEntry<bool> isSwordS1; |
|
public static ConfigEntry<bool> isSwordS2; |
|
public static ConfigEntry<bool> isHalberdS1; //CONFIG ENTRY FOR BEPINEX CONFIGURATION MANAGER |
|
|
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|