Skip to content

Commit 63388af

Browse files
committed
First working version
1 parent db40caf commit 63388af

2 files changed

Lines changed: 48 additions & 16 deletions

File tree

ModConfigDynVarBridge/ModConfigDynVarBridge.cs

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using System.Reflection.Emit;
25
using FrooxEngine;
36
using HarmonyLib;
47
using NeosModLoader;
@@ -18,9 +21,10 @@ public class ModConfigDynVarBridge : NeosMod
1821

1922
public override void OnEngineInit()
2023
{
24+
_config = GetConfiguration();
2125
Harmony harmony = new Harmony("net.KyuubiYoru.ModConfigDynVarBridge");
2226
harmony.PatchAll();
23-
_config = GetConfiguration();
27+
2428
}
2529

2630
[HarmonyPatch(typeof(Userspace))]
@@ -37,32 +41,58 @@ static void OnAttachPostFix(Userspace __instance)
3741
foreach (NeosModBase mod in ModLoader.Mods())
3842
{
3943
ModConfiguration config = mod.GetConfiguration();
40-
if (config !=null)
44+
if (config != null)
4145
{
46+
Slot modConfigSlot = _configSlot.AddSlot(mod.Name);
47+
DynamicVariableSpace space =
48+
(DynamicVariableSpace) modConfigSlot.AttachComponent(typeof(DynamicVariableSpace));
49+
space.OnlyDirectBinding.Value = true;
50+
space.SpaceName.Value = mod.Name;
51+
4252
foreach (ModConfigurationKey key in config.ConfigurationItemDefinitions)
4353
{
44-
54+
if (!key.InternalAccessOnly)
55+
{
56+
Debug("Try to add"+key.Name);
57+
MethodInfo method = typeof(UserspacePatch).GetMethod(nameof(SetupDynVar));
58+
MethodInfo generic = method?.MakeGenericMethod(key.ValueType());
59+
generic?.Invoke(__instance, new object[] {modConfigSlot, mod, key});
60+
}
4561
}
4662
}
4763
}
64+
}
65+
catch (Exception e)
66+
{
67+
Debug("OnAttach");
68+
Debug(e.Message);
69+
Debug(e.StackTrace);
70+
}
71+
}
4872

49-
//IkCullingPatch.UserSpaceWorld =
50-
// (DynamicVariableSpace)IkCullingPatch.ConfigSlot.AttachComponent(typeof(DynamicVariableSpace));
51-
//IkCullingPatch.UserSpaceWorld.OnlyDirectBinding.Value = true;
52-
//IkCullingPatch.UserSpaceWorld.SpaceName.Value = "IkCullingConfig";
53-
54-
//DynamicValueVariable<bool> value = (DynamicValueVariable<bool>)IkCullingPatch.ConfigSlot.AttachComponent(typeof(DynamicValueVariable<bool>));
55-
//value.VariableName.Value = "IkCullingConfig/Enable";
56-
//value.Value.Changed += changeable => Config.Set(Enabled, ((SyncField<bool>)changeable).Value);
73+
public static void SetupDynVar<T>(Slot slot, NeosModBase mod, ModConfigurationKey key)
74+
{
75+
try
76+
{
77+
DynamicValueVariable<T> dynVar = (DynamicValueVariable<T>) slot.AttachComponent(typeof(DynamicValueVariable<T>));
78+
if (dynVar == null)
79+
{
80+
Debug("dynVar is null");
81+
}
5782

83+
mod.GetConfiguration().TryGetValue((ModConfigurationKey<T>) key, out T value);
84+
dynVar.Value.Value = value;
85+
dynVar.VariableName.Value = $"{mod.Name}/{key.Name}";
86+
dynVar.Value.Changed += changeable => mod.GetConfiguration().Set(key, ((SyncField<T>) changeable).Value);
5887

88+
//key.OnChanged += value => dynVar.Value.Value = (T)value;
5989

6090
}
6191
catch (Exception e)
6292
{
63-
Debug("OnAttach");
6493
Debug(e.Message);
65-
Debug(e.StackTrace);
94+
Debug(e.ToString());
95+
6696
}
6797
}
6898
}

ModConfigDynVarBridge/ModConfigDynVarBridge.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
77
<OutputType>Library</OutputType>
88
<AppDesignerFolder>Properties</AppDesignerFolder>
9-
<RootNamespace>ModNameGoesHere</RootNamespace>
10-
<AssemblyName>ModNameGoesHere</AssemblyName>
9+
<RootNamespace>ModConfigDynVarBridge</RootNamespace>
10+
<AssemblyName>ModConfigDynVarBridge</AssemblyName>
1111
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<Deterministic>true</Deterministic>
@@ -22,6 +22,7 @@
2222
<DefineConstants>DEBUG;TRACE</DefineConstants>
2323
<ErrorReport>prompt</ErrorReport>
2424
<WarningLevel>4</WarningLevel>
25+
<LangVersion>latest</LangVersion>
2526
</PropertyGroup>
2627
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2728
<DebugType>pdbonly</DebugType>
@@ -30,6 +31,7 @@
3031
<DefineConstants>TRACE</DefineConstants>
3132
<ErrorReport>prompt</ErrorReport>
3233
<WarningLevel>4</WarningLevel>
34+
<LangVersion>latest</LangVersion>
3335
</PropertyGroup>
3436
<ItemGroup>
3537
<Reference Include="0Harmony">
@@ -55,6 +57,6 @@
5557
</ItemGroup>
5658
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5759
<PropertyGroup>
58-
<PostBuildEvent>copy "$(TargetDir)\$(TargetFileName)" "C:\Program Files (x86)\Steam\steamapps\common\NeosVR\nml_mods\"</PostBuildEvent>
60+
<PostBuildEvent>xcopy "$(TargetDir)$(TargetFileName)" E:\NeosVR\Install\app\nml_mods\ /y</PostBuildEvent>
5961
</PropertyGroup>
6062
</Project>

0 commit comments

Comments
 (0)