Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 25 additions & 40 deletions CommunityBugFixCollection/BreakDragAndDropCopiedComponentDrives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,46 @@
using FrooxEngine;
using FrooxEngine.UIX;
using HarmonyLib;
using System.Reflection;
using System.Reflection.Emit;

namespace CommunityBugFixCollection
{
[HarmonyPatchCategory(nameof(BreakDragAndDropCopiedComponentDrives))]
[HarmonyPatch(typeof(SlotComponentReceiver), nameof(SlotComponentReceiver.TryReceive))]
internal sealed class BreakDragAndDropCopiedComponentDrives : ResoniteBugFixMonkey<BreakDragAndDropCopiedComponentDrives>
{
public override IEnumerable<string> Authors => Contributors.Banane9;
public override IEnumerable<string> Authors { get; } = [.. Contributors.Banane9, .. Contributors.Onan];

private static bool Prefix(SlotComponentReceiver __instance, IEnumerable<IGrabbable> items, Canvas.InteractionData eventData, out bool __result)
public static MethodBase TargetMethod()
{
__result = false;
#pragma warning disable CS8603 // Possible null reference return.
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
Type stateMachineType = typeof(SlotComponentReceiver).InnerTypes().FirstOrDefault(x => x.Name.StartsWith("<>") && x.InnerTypes().Any());
MethodInfo stolencodethingy = AccessTools.GetDeclaredMethods(stateMachineType).FirstOrDefault(x => x.Name == "<TryReceive>b__1");
return stolencodethingy;
#pragma warning restore CS8603 // Possible null reference return.
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
}

if (__instance.Target.Target is null)
return false;

foreach (var item in items)
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> Codes)
{
List<CodeInstruction> newcodes = new List<CodeInstruction>();
foreach (CodeInstruction code in Codes)
{
foreach (ReferenceProxy componentsInChild in item.Slot.GetComponentsInChildren<ReferenceProxy>())
if (code.operand != null)
{
if (componentsInChild.Reference.Target is not Component component || __instance.Target.Target == component.Slot)
if(code.operand.ToString().Contains("CopyComponent")){

Check warning on line 34 in CommunityBugFixCollection/BreakDragAndDropCopiedComponentDrives.cs

View workflow job for this annotation

GitHub Actions / Build

Dereference of a possibly null reference.

Check warning on line 34 in CommunityBugFixCollection/BreakDragAndDropCopiedComponentDrives.cs

View workflow job for this annotation

GitHub Actions / Build

Dereference of a possibly null reference.

newcodes.Add(new CodeInstruction(OpCodes.Ldc_I4_0));
newcodes.Add(new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(FrooxEngine.Slot), "DuplicateComponent")));
continue;

__instance.StartTask(async () =>
{
var contextMenu = await __instance.LocalUser.OpenContextMenu(__instance, eventData.source.Slot);

var copyItem = contextMenu.AddItem("Inspector.Actions.CopyComponent".AsLocaleKey(), (Uri)null!, RadiantUI_Constants.Hero.GREEN);
var moveItem = contextMenu.AddItem("Inspector.Actions.MoveComponent".AsLocaleKey(), (Uri)null!, RadiantUI_Constants.Hero.PURPLE);
var cancelItem = contextMenu.AddItem("General.Cancel".AsLocaleKey(), (Uri)null!, colorX.White);

copyItem.Button.LocalPressed += delegate
{
__instance.Target.Target.DuplicateComponent(component);
__instance.LocalUser.CloseContextMenu(__instance);
};

moveItem.Button.LocalPressed += delegate
{
__instance.Target.Target.MoveComponent(component);
__instance.LocalUser.CloseContextMenu(__instance);
};

cancelItem.Button.LocalPressed += delegate
{
__instance.LocalUser.CloseContextMenu(__instance);
};
});

__result = true;
return false;
}
}
newcodes.Add(code);
}

return false;
Logger.Info(newcodes);
return newcodes;
}
}
}
3 changes: 2 additions & 1 deletion CommunityBugFixCollection/CommunityBugFixCollection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<PackageId>CommunityBugFixCollection</PackageId>
<Title>Community Bug-Fix Collection</Title>
<Authors>Banane9; Nytra; art0007i; LeCloutPanda; goat; __Choco__; LJ; 989onan</Authors>
<Version>0.9.0-beta</Version>
<Version>0.9.0-beta</Version>
<Description>This MonkeyLoader mod for Resonite that fixes various small Resonite-issues that are still open.</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
<RepositoryUrl>$(PackageProjectUrl).git</RepositoryUrl>
<PackageProjectUrl>https://github.com/ResoniteModdingGroup/CommunityBugFixCollection</PackageProjectUrl>
<RepositoryUrl>$(PackageProjectUrl).git</RepositoryUrl>
<PackageTags>mod; mods; monkeyloader; resonite; component; attacher; selector; protoflux; node; picker; search; favorites</PackageTags>
Expand Down
87 changes: 87 additions & 0 deletions CommunityBugFixCollection/DontRaycastDeveloper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using FrooxEngine;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;

namespace CommunityBugFixCollection
{
[HarmonyPatchCategory(nameof(DontRaycastDeveloper))]
[HarmonyPatch(typeof(FrooxEngine.RaycastDriver), nameof(FrooxEngine.RaycastDriver.OnCommonUpdate))]
internal sealed class DontRaycastDeveloper : ResoniteBugFixMonkey<DontRaycastDeveloper>
{

public override IEnumerable<string> Authors { get; } = [.. Contributors.Onan];

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//Debugger.Launch();
List<CodeInstruction> instructionList = [.. instructions];


int index = 0;
int start = 0;
int stop = 0;
CodeInstruction Filter = new CodeInstruction(OpCodes.Nop);
foreach (CodeInstruction inst in instructionList)
{

if (inst.operand?.ToString()?.ToLower()?.Contains("ignorehierarchy") == true)
{
if(start == 0)
{
start = index;
}

}
if (inst.operand?.ToString()?.ToLower()?.Contains("icollider") == true && inst.operand?.ToString()?.ToLower()?.Contains("bool") == true && inst.operand?.ToString()?.ToLower()?.Contains("invoke") == true)
{
if (stop == 0)
{
stop = index;
}
}
if (inst.opcode == OpCodes.Ldfld && inst.operand?.ToString()?.Contains("Filter") == true)
{
Filter = inst;
}
index++;
}


//note to self, loading "this" before trying to load a "this" variable on the stack is important - @989onan
List<CodeInstruction> newinstructions =
[
new CodeInstruction(OpCodes.Ldarg_0),
instructionList[start],
new CodeInstruction(OpCodes.Ldloc_S,8),
new CodeInstruction(OpCodes.Ldarg_0),
Filter,
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(DontRaycastDeveloper), "DontRaycastDeveloperFilter")),
];
instructionList.RemoveRange(start-1, (stop+2) - start);



instructionList.InsertRange(start - 1/*this is needed since start lands on "ignore hiearchy" which is at the beginning*/, newinstructions);


return instructionList;

}


//recreates the if statement, allowing for full control over this check on raycasts and doing whatever we want.
public static bool DontRaycastDeveloperFilter(SyncRef<Slot> IgnoreHierarchy, RaycastHit hit, SyncDelegate<Func<ICollider, bool>> Filter) {
if (!Enabled)
{
return (IgnoreHierarchy.Target == null || !hit.Collider.Slot.IsChildOf(IgnoreHierarchy.Target, true)) && (Filter.Target == null || Filter.Target(hit.Collider)); //this is where we use the default behavior.
}
return (IgnoreHierarchy.Target == null || !hit.Collider.Slot.IsChildOf(IgnoreHierarchy.Target, true)) && (Filter.Target == null || Filter.Target(hit.Collider)) && hit.Collider.Slot.FindParent(o=>o.Name == "Gizmo")?.GetComponent<SlotGizmo>() == null; //this is where we can specify "STOP RAYCASTING DEVELOPER!!!"
}
}
}
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
</PropertyGroup>

<PropertyGroup Condition="'$(ResonitePath)'==''">
<ResonitePath Condition="Exists('D:/Files/Games/Resonite/app/')">D:/Files/Games/Resonite/app</ResonitePath>
<ResonitePath Condition="Exists('D:/SteamLibrary//steamapps/common/Resonite/')">D:/SteamLibrary//steamapps/common/Resonite</ResonitePath>
<ResonitePath Condition="Exists('G:/SteamLibrary/steamapps/common/Resonite')">G:/SteamLibrary\steamapps\common\Resonite</ResonitePath>
<ResonitePath Condition="Exists('D:/Files/Games/Resonite/app/')">D:/Files/Games/Resonite/app/</ResonitePath>
<ResonitePath Condition="Exists('D:/SteamLibrary/steamapps/common/Resonite/')">D:/SteamLibrary/steamapps/common/Resonite/</ResonitePath>
<ResonitePath Condition="Exists('G:/SteamLibrary/steamapps/common/Resonite/')">G:/SteamLibrary\steamapps\common\Resonite\</ResonitePath>
</PropertyGroup>

<PropertyGroup Condition="'$(ResoniteCachePath)' == ''">
Expand Down
Loading