Skip to content

Commit b405ad5

Browse files
committed
Correct ProtoFlux value casts of bytes to other values
Adds a fix for Yellow-Dog-Man/Resonite-Issues#2257
1 parent 8f4a5b9 commit b405ad5

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

CommunityBugFixCollection/CommunityBugFixCollection.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
<PackageReference Include="Resonite.Elements.Quantity" Version="1.2.3" />
4545
<PackageReference Include="Resonite.FrooxEngine" Version="2025.3.21.23" />
4646
<PackageReference Include="Resonite.FrooxEngine.Store" Version="1.0.3" />
47+
<PackageReference Include="Resonite.ProtoFlux.Core" Version="1.2.0" />
48+
<PackageReference Include="Resonite.ProtoFlux.Nodes.Core" Version="1.2.0" />
4749
<PackageReference Include="Resonite.ProtoFluxBindings" Version="2025.5.18.24" />
4850
<PackageReference Include="Resonite.SkyFrost.Base" Version="2.1.0" />
4951
<PackageReference Include="Resonite.SkyFrost.Base.Models" Version="2.1.0" />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using HarmonyLib;
2+
using MonkeyLoader.Resonite;
3+
using ProtoFlux.Core;
4+
using ProtoFlux.Runtimes.Execution;
5+
using ProtoFlux.Runtimes.Execution.Nodes.Casts;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Reflection;
10+
using System.Text;
11+
12+
namespace CommunityBugFixCollection
13+
{
14+
internal sealed class CorrectByteCasting : ResoniteMonkey<CorrectByteCasting>
15+
{
16+
public override IEnumerable<string> Authors => Contributors.Banane9;
17+
18+
public override bool CanBeDisabled => true;
19+
20+
protected override bool OnEngineReady()
21+
{
22+
var targets = AccessTools.GetTypesFromAssembly(typeof(Cast_byte_To_int).Assembly)
23+
.Select(type => (Type: type, ValueCast: type.GetCustomAttribute<ValueCastAttribute>()))
24+
.Where(candidate => candidate.ValueCast?.From == typeof(byte))
25+
.Select(candidate => (candidate.ValueCast, Method: AccessTools.DeclaredMethod(candidate.Type, nameof(Cast_byte_To_int.Compute))))
26+
.Where(target => target.Method is not null);
27+
28+
var computePrefix = AccessTools.DeclaredMethod(typeof(CorrectByteCasting), nameof(ComputePrefix));
29+
30+
foreach (var target in targets)
31+
Harmony.Patch(target.Method, computePrefix.MakeGenericMethod(target.ValueCast.To));
32+
33+
return true;
34+
}
35+
36+
private static bool ComputePrefix<T>(ExecutionContext context, ref T __result)
37+
where T : unmanaged
38+
{
39+
if (!Enabled)
40+
return true;
41+
42+
var value = (object)0.ReadValue<byte>(context);
43+
__result = (T)(Convert.ChangeType(value, typeof(T)) ?? default(T));
44+
45+
return false;
46+
}
47+
}
48+
}

CommunityBugFixCollection/Locale/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"CommunityBugFixCollection.ColorDisplayValueProxy.Description": "Sorgt dafür, dass ValueDisplay<color> Nodes eine ValueProxySource Komponente haben.",
1717
"CommunityBugFixCollection.ColorXNodeNamesSpacing.Description": "Korrigiert die Schreibweise der Namen von ProtoFlux Nodes die ColorX enthalten.",
1818
"CommunityBugFixCollection.CopySyncMemberToClipboardAction.Description": "Fügt eine Kopieren Aktion zu Feldern in Inspektoren hinzu, die keine Referenzen sind.",
19+
"CommunityBugFixCollection.CorrectByteCasting.Description": "Korrigiert die Konvertierung von bytes in andere Werte mittels ProtoFlux Value Casts.",
1920
"CommunityBugFixCollection.CorrectMaterialGizmoScaling.Description": "Verhindert, dass das MaterialGizmo zweimal skaliert wird, wenn man Editieren auf dem Materialwerzeug nutzt.",
2021
"CommunityBugFixCollection.DuplicateAndMoveMultipleGrabbedItems.Description": "Verhindert, dass Referenzen zwischen mehreren duplizierten oder zwischen Welten transferierten Objekten gebrochen werden.",
2122
"CommunityBugFixCollection.FireBrushToolDequipEvents.Description": "Sorgt dafür, dass von BrushTool abgeleitete Werkzeuge OnDequipped Events abschicken.",

CommunityBugFixCollection/Locale/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"CommunityBugFixCollection.ColorDisplayValueProxy.Description": "Fixes ValueDisplay<color> not having a ValueProxySource component.",
1717
"CommunityBugFixCollection.ColorXNodeNamesSpacing.Description": "Fixes ProtoFlux node names containing ColorX being spaced wrong.",
1818
"CommunityBugFixCollection.CopySyncMemberToClipboardAction.Description": "Adds Copy to Clipboard action on any non-reference member fields in Inspectors.",
19+
"CommunityBugFixCollection.CorrectByteCasting.Description": "Fixes ProtoFlux value casts from byte to some other value converting incorrectly.",
1920
"CommunityBugFixCollection.CorrectMaterialGizmoScaling.Description": "Fixes the MaterialGizmo being scaled twice when using Edit on the Material Tool.",
2021
"CommunityBugFixCollection.DuplicateAndMoveMultipleGrabbedItems.Description": "Fixes references between multiple duplicated or transferred-between-worlds items breaking.",
2122
"CommunityBugFixCollection.FireBrushToolDequipEvents.Description": "Fixes tools derived from BrushTool not firing OnDequipped events.",

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ just disable them in the settings in the meantime.
4545
* URLs to text files or Resonite Packages failing to import instead of appearing as a hyperlink (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/785)
4646
* References in multiple duplicated or transferred-between-worlds items breaking (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/984)
4747
* UserInspectors not listing existing users in the session for non-host users (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/1964)
48+
* ProtoFlux value casts from byte to other values converting incorrectly (mono / graphical client only) (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/2257)
4849
* Grid World grid being off-center (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/2754)
4950
* Animators updating all associated fields every frame while enabled but not playing (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/3480)
5051
* Direct cursor size becoming very large when snapped to an object much closer than the true cursor (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/3654)

0 commit comments

Comments
 (0)