quantum-space-buddies/QSB/ItemSync/Patches/ItemPatches.cs

103 lines
4.8 KiB
C#
Raw Normal View History

2021-03-12 21:46:02 +00:00
using OWML.Common;
using QSB.Events;
2021-02-25 13:52:49 +00:00
using QSB.Patches;
2021-02-23 14:42:18 +00:00
using QSB.Utility;
2021-02-25 13:52:49 +00:00
using QSB.WorldSync;
2021-02-23 14:42:18 +00:00
using UnityEngine;
namespace QSB.ItemSync.Patches
{
2021-02-24 10:45:25 +00:00
internal class ItemPatches : QSBPatch
2021-02-23 14:42:18 +00:00
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
public override void DoPatches()
{
2021-03-13 10:17:52 +00:00
QSBCore.HarmonyHelper.AddPrefix<ItemTool>("MoveItemToCarrySocket", typeof(ItemPatches), nameof(ItemTool_MoveItemToCarrySocket));
QSBCore.HarmonyHelper.AddPrefix<ItemTool>("SocketItem", typeof(ItemPatches), nameof(ItemTool_SocketItem));
QSBCore.HarmonyHelper.AddPrefix<ItemTool>("StartUnsocketItem", typeof(ItemPatches), nameof(ItemTool_StartUnsocketItem));
QSBCore.HarmonyHelper.AddPrefix<ItemTool>("CompleteUnsocketItem", typeof(ItemPatches), nameof(ItemTool_CompleteUnsocketItem));
QSBCore.HarmonyHelper.AddPrefix<ItemTool>("DropItem", typeof(ItemPatches), nameof(ItemTool_DropItem));
QSBCore.HarmonyHelper.AddPrefix<NomaiRemoteCameraPlatform>("Update", typeof(ItemPatches), nameof(Platform_ReturnFalse));
QSBCore.HarmonyHelper.AddPrefix<NomaiRemoteCameraPlatform>("OnSocketableRemoved", typeof(ItemPatches), nameof(Platform_ReturnFalse));
QSBCore.HarmonyHelper.AddPrefix<NomaiRemoteCameraPlatform>("OnSocketableDonePlacing", typeof(ItemPatches), nameof(Platform_ReturnFalse));
QSBCore.HarmonyHelper.AddPrefix<NomaiRemoteCameraPlatform>("OnPedestalContact", typeof(ItemPatches), nameof(Platform_ReturnFalse));
QSBCore.HarmonyHelper.AddPrefix<NomaiRemoteCameraStreaming>("FixedUpdate", typeof(ItemPatches), nameof(Platform_ReturnFalse));
QSBCore.HarmonyHelper.AddPrefix<NomaiRemoteCameraStreaming>("OnSectorOccupantAdded", typeof(ItemPatches), nameof(Platform_ReturnFalse));
QSBCore.HarmonyHelper.AddPrefix<NomaiRemoteCameraStreaming>("OnSectorOccupantRemoved", typeof(ItemPatches), nameof(Platform_ReturnFalse));
QSBCore.HarmonyHelper.AddPrefix<NomaiRemoteCameraStreaming>("OnEntry", typeof(ItemPatches), nameof(Platform_ReturnFalse));
QSBCore.HarmonyHelper.AddPrefix<NomaiRemoteCameraStreaming>("OnExit", typeof(ItemPatches), nameof(Platform_ReturnFalse));
2021-02-23 14:42:18 +00:00
}
public override void DoUnpatches()
{
2021-03-07 20:12:38 +00:00
// TODO : add this
2021-02-23 14:42:18 +00:00
}
2021-03-07 09:27:23 +00:00
public static bool Platform_ReturnFalse() => false;
2021-03-06 23:59:44 +00:00
2021-02-25 22:45:32 +00:00
public static bool ItemTool_MoveItemToCarrySocket(OWItem item)
{
var itemId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(item));
QSBEventManager.FireEvent(EventNames.QSBMoveToCarry, itemId);
return true;
}
2021-02-23 14:42:18 +00:00
public static bool ItemTool_SocketItem(OWItem ____heldItem, OWItemSocket socket)
{
2021-02-25 22:45:32 +00:00
var socketId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(socket));
var itemId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(____heldItem));
QSBEventManager.FireEvent(EventNames.QSBSocketItem, socketId, itemId, SocketEventType.Socket);
2021-02-23 14:42:18 +00:00
return true;
}
2021-02-25 22:45:32 +00:00
public static bool ItemTool_StartUnsocketItem(OWItemSocket socket)
2021-02-23 14:42:18 +00:00
{
2021-02-25 22:45:32 +00:00
var socketId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(socket));
QSBEventManager.FireEvent(EventNames.QSBSocketItem, socketId, 0, SocketEventType.StartUnsocket);
return true;
}
2021-02-26 13:12:29 +00:00
public static bool ItemTool_CompleteUnsocketItem(OWItem ____heldItem)
{
var itemId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(____heldItem));
QSBEventManager.FireEvent(EventNames.QSBSocketItem, 0, itemId, SocketEventType.CompleteUnsocket);
2021-02-25 22:45:32 +00:00
return true;
2021-02-23 14:42:18 +00:00
}
public static bool ItemTool_DropItem(RaycastHit hit, OWRigidbody targetRigidbody, DetachableFragment detachableFragment, ref OWItem ____heldItem)
{
Locator.GetPlayerAudioController().PlayDropItem(____heldItem.GetItemType());
var hitGameObject = hit.collider.gameObject;
var gameObject2 = hitGameObject;
var sectorGroup = gameObject2.GetComponent<ISectorGroup>();
Sector sector = null;
while (sectorGroup == null && gameObject2.transform.parent != null)
{
gameObject2 = gameObject2.transform.parent.gameObject;
sectorGroup = gameObject2.GetComponent<ISectorGroup>();
}
if (sectorGroup != null)
{
sector = sectorGroup.GetSector();
}
2021-02-24 10:45:25 +00:00
var parent = (detachableFragment != null)
? detachableFragment.transform
2021-02-23 14:42:18 +00:00
: targetRigidbody.transform;
2021-02-25 13:52:49 +00:00
var objectId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(____heldItem));
2021-02-23 14:42:18 +00:00
____heldItem.DropItem(hit.point, hit.normal, parent, sector, detachableFragment);
____heldItem = null;
Locator.GetToolModeSwapper().UnequipTool();
2021-02-25 13:52:49 +00:00
var parentSector = parent.GetComponentInChildren<Sector>();
if (parentSector != null)
{
var localPos = parentSector.transform.InverseTransformPoint(hit.point);
QSBEventManager.FireEvent(EventNames.QSBDropItem, objectId, localPos, hit.normal, parentSector);
return false;
}
2021-03-12 21:46:02 +00:00
DebugLog.ToConsole($"Error - No sector found for rigidbody {targetRigidbody.name}!.", MessageType.Error);
2021-02-23 14:42:18 +00:00
return false;
}
}
}