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

308 lines
7.5 KiB
C#
Raw Normal View History

2022-03-23 16:05:46 -07:00
using HarmonyLib;
using QSB.Patches;
2022-03-23 21:44:21 -07:00
using QSB.Player;
using System.Linq;
2022-03-23 21:17:10 -07:00
using UnityEngine;
2022-03-23 16:05:46 -07:00
namespace QSB.ItemSync.Patches;
internal class ItemRemotePatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
2022-03-23 21:54:43 -07:00
#region OWItem
2022-03-23 21:17:10 -07:00
[HarmonyReversePatch]
2022-03-23 16:05:46 -07:00
[HarmonyPatch(typeof(OWItem), nameof(OWItem.PickUpItem))]
2022-03-23 21:54:43 -07:00
private static void base_PickUpItem(OWItem instance, Transform holdTranform) { }
2022-03-23 21:17:10 -07:00
[HarmonyPrefix]
[HarmonyPatch(typeof(DreamLanternItem), nameof(DreamLanternItem.PickUpItem))]
2022-03-23 21:54:43 -07:00
private static bool PickUpItem(DreamLanternItem __instance,
2022-03-23 21:17:10 -07:00
Transform holdTranform)
2022-03-23 16:05:46 -07:00
{
2022-03-23 21:17:10 -07:00
if (!Remote)
{
return true;
}
2022-03-23 21:54:43 -07:00
base_PickUpItem(__instance, holdTranform);
2022-03-23 21:17:10 -07:00
if (__instance._lanternType == DreamLanternType.Functioning)
{
// __instance.enabled = true;
2022-03-23 21:17:10 -07:00
}
if (__instance._lanternController != null)
{
__instance._lanternController.enabled = true;
__instance._lanternController.SetDetectorScaleCompensation(__instance._lanternController.transform.lossyScale);
__instance._lanternController.SetHeldByPlayer(true);
// Locator.GetPlayerController().SetDreamLantern(__instance);
2022-03-23 21:17:10 -07:00
}
2022-03-23 16:05:46 -07:00
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(VisionTorchItem), nameof(VisionTorchItem.PickUpItem))]
private static bool PickUpItem(VisionTorchItem __instance,
Transform holdTranform)
{
if (!Remote)
{
return true;
}
base_PickUpItem(__instance, holdTranform);
if (__instance._visionBeam != null)
{
__instance._visionBeam.localScale = Vector3.one * 5f;
}
/*
foreach (var renderer in __instance._worldModelRenderers)
{
renderer.SetActivation(false);
}
foreach (var renderer in __instance._viewModelRenderers)
{
renderer.SetActivation(true);
}
__instance.enabled = true;
*/
return false;
}
2022-03-23 21:46:30 -07:00
[HarmonyPrefix]
[HarmonyPatch(typeof(SimpleLanternItem), nameof(SimpleLanternItem.PickUpItem))]
2022-03-23 21:54:43 -07:00
private static bool PickUpItem(SimpleLanternItem __instance,
2022-03-23 21:46:30 -07:00
Transform holdTranform)
{
if (!Remote)
{
return true;
}
if (__instance._lit)
{
// Locator.GetFlashlight().TurnOff();
}
2022-03-23 21:46:30 -07:00
if (__instance._lightSourceVol != null)
{
__instance._lightSourceShape.radius = __instance._origLightSourceShapeRadius / holdTranform.localScale.x;
}
2022-03-23 21:54:43 -07:00
base_PickUpItem(__instance, holdTranform);
2022-03-23 21:46:30 -07:00
return false;
}
2022-03-23 21:17:10 -07:00
[HarmonyReversePatch]
2022-03-23 16:05:46 -07:00
[HarmonyPatch(typeof(OWItem), nameof(OWItem.DropItem))]
2022-03-23 21:54:43 -07:00
private static void base_DropItem(OWItem instance,
2022-03-23 21:17:10 -07:00
Vector3 position,
Vector3 normal,
Transform parent,
Sector sector,
IItemDropTarget customDropTarget) { }
[HarmonyPrefix]
[HarmonyPatch(typeof(DreamLanternItem), nameof(DreamLanternItem.DropItem))]
2022-03-23 21:54:43 -07:00
private static bool DropItem(DreamLanternItem __instance,
2022-03-23 21:17:10 -07:00
Vector3 position,
Vector3 normal,
Transform parent,
Sector sector,
IItemDropTarget customDropTarget)
2022-03-23 16:05:46 -07:00
{
2022-03-23 21:17:10 -07:00
if (!Remote)
{
return true;
}
2022-03-23 21:54:43 -07:00
base_DropItem(__instance, position, normal, parent, sector, customDropTarget);
// __instance.enabled = false;
2022-03-23 21:17:10 -07:00
if (__instance._lanternController != null)
{
__instance._lanternController.SetDetectorScaleCompensation(__instance._lanternController.transform.lossyScale);
__instance._lanternController.SetHeldByPlayer(false);
2022-03-23 21:17:10 -07:00
__instance._lanternController.enabled = __instance._lanternController.IsLit();
// Locator.GetPlayerController().SetDreamLantern(null);
2022-03-23 21:17:10 -07:00
}
2022-03-23 16:05:46 -07:00
return false;
}
2022-03-23 21:54:43 -07:00
[HarmonyPrefix]
[HarmonyPatch(typeof(VisionTorchItem), nameof(VisionTorchItem.DropItem))]
private static bool DropItem(VisionTorchItem __instance,
Vector3 position,
Vector3 normal,
Transform parent,
Sector sector,
IItemDropTarget customDropTarget)
{
if (!Remote)
{
return true;
}
// if (Locator.GetDreamWorldController().IsInDream())
// {
2022-03-23 21:54:43 -07:00
base_DropItem(__instance, position, normal, parent, sector, customDropTarget);
// }
2022-03-23 21:54:43 -07:00
if (__instance._visionBeam != null)
{
__instance._visionBeam.localScale = Vector3.one;
}
/*
2022-03-23 21:54:43 -07:00
foreach (var renderer in __instance._worldModelRenderers)
{
renderer.SetActivation(true);
}
foreach (var renderer in __instance._viewModelRenderers)
{
renderer.SetActivation(false);
}
__instance.enabled = false;
*/
2022-03-23 21:54:43 -07:00
return false;
}
2022-03-23 21:17:10 -07:00
[HarmonyReversePatch]
2022-03-23 16:05:46 -07:00
[HarmonyPatch(typeof(OWItem), nameof(OWItem.SocketItem))]
2022-03-23 21:54:43 -07:00
private static void base_SocketItem(OWItem instance, Transform socketTransform, Sector sector) { }
2022-03-23 21:17:10 -07:00
[HarmonyPrefix]
[HarmonyPatch(typeof(DreamLanternItem), nameof(DreamLanternItem.SocketItem))]
2022-03-23 22:09:23 -07:00
private static bool SocketItem(DreamLanternItem __instance,
2022-03-23 21:17:10 -07:00
Transform socketTransform, Sector sector)
2022-03-23 16:05:46 -07:00
{
2022-03-23 21:17:10 -07:00
if (!Remote)
{
return true;
}
2022-03-27 09:21:12 +01:00
base_SocketItem(__instance, socketTransform, sector);
// __instance.enabled = false;
2022-03-23 21:17:10 -07:00
if (__instance._lanternController != null)
{
__instance._lanternController.SetDetectorScaleCompensation(__instance._lanternController.transform.lossyScale);
__instance._lanternController.SetSocketed(true);
__instance._lanternController.SetHeldByPlayer(false);
__instance._lanternController.enabled = __instance._lanternController.IsLit();
// Locator.GetPlayerController().SetDreamLantern(null);
2022-03-23 21:17:10 -07:00
}
2022-03-23 16:05:46 -07:00
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(VisionTorchItem), nameof(VisionTorchItem.SocketItem))]
private static bool SocketItem(VisionTorchItem __instance,
Transform socketTransform, Sector sector)
{
if (!Remote)
{
return true;
}
base_SocketItem(__instance, socketTransform, sector);
if (__instance._visionBeam != null)
{
__instance._visionBeam.localScale = Vector3.one;
}
/*
foreach (var renderer in __instance._worldModelRenderers)
{
renderer.SetActivation(true);
}
foreach (var renderer in __instance._viewModelRenderers)
{
renderer.SetActivation(false);
}
__instance.enabled = false;
*/
return false;
}
2022-03-23 21:17:10 -07:00
#endregion
2022-03-23 21:54:43 -07:00
#region OWItemSocket
2022-03-23 21:17:10 -07:00
[HarmonyReversePatch]
2022-03-23 16:05:46 -07:00
[HarmonyPatch(typeof(OWItemSocket), nameof(OWItemSocket.PlaceIntoSocket))]
2022-03-23 21:54:43 -07:00
private static bool base_PlaceIntoSocket(OWItemSocket instance, OWItem item) => default;
2022-03-23 21:17:10 -07:00
[HarmonyPrefix]
[HarmonyPatch(typeof(DreamLanternSocket), nameof(DreamLanternSocket.PlaceIntoSocket))]
2022-03-23 21:54:43 -07:00
private static bool PlaceIntoSocket(DreamLanternSocket __instance, ref bool __result,
2022-03-23 21:17:10 -07:00
OWItem item)
2022-03-23 16:05:46 -07:00
{
2022-03-23 21:17:10 -07:00
if (!Remote)
{
return true;
}
2022-03-23 21:54:43 -07:00
if (base_PlaceIntoSocket(__instance, item))
2022-03-23 21:17:10 -07:00
{
// Locator.GetDreamWorldController().SetPlayerLanternSocket(__instance);
2022-03-23 21:17:10 -07:00
__result = true;
return false;
}
__result = false;
2022-03-23 16:05:46 -07:00
return false;
}
2022-03-23 21:17:10 -07:00
[HarmonyReversePatch]
2022-03-23 16:05:46 -07:00
[HarmonyPatch(typeof(OWItemSocket), nameof(OWItemSocket.RemoveFromSocket))]
2022-03-23 21:54:43 -07:00
private static OWItem base_RemoveFromSocket(OWItemSocket instance) => default;
2022-03-23 21:17:10 -07:00
[HarmonyPrefix]
[HarmonyPatch(typeof(DreamLanternSocket), nameof(DreamLanternSocket.RemoveFromSocket))]
2022-03-23 21:54:43 -07:00
private static bool RemoveFromSocket(DreamLanternSocket __instance, ref OWItem __result)
2022-03-23 16:05:46 -07:00
{
2022-03-23 21:17:10 -07:00
if (!Remote)
{
return true;
}
2022-03-23 21:54:43 -07:00
var owitem = base_RemoveFromSocket(__instance);
if (owitem != null)
{
// Locator.GetDreamWorldController().SetPlayerLanternSocket(null);
}
2022-03-23 21:17:10 -07:00
__result = owitem;
2022-03-23 16:05:46 -07:00
return false;
}
2022-03-23 21:17:10 -07:00
2022-03-23 21:44:21 -07:00
[HarmonyPrefix]
[HarmonyPatch(typeof(SlideReelSocket), nameof(SlideReelSocket.RemoveFromSocket))]
2022-03-23 21:54:43 -07:00
private static bool RemoveFromSocket(SlideReelSocket __instance, ref OWItem __result)
2022-03-23 21:44:21 -07:00
{
if (!Remote)
{
return true;
}
var socketedItem = (SlideReelItem)__instance._socketedItem;
var player = QSBPlayerManager.PlayerList.First(x => x.HeldItem?.AttachedObject == socketedItem);
2022-03-23 21:44:21 -07:00
socketedItem.SetSocketLocalDir(__instance.CalcCorrectUnsocketDir(player.Camera.transform));
2022-03-23 21:54:43 -07:00
__result = base_RemoveFromSocket(__instance);
2022-03-23 21:44:21 -07:00
return false;
}
2022-03-23 21:17:10 -07:00
#endregion
2022-03-23 16:05:46 -07:00
}