Skip to content

Commit c33d4cd

Browse files
authored
Merge pull request #31 from dfgHiatus/feat/update-bugfix-thingy
feat(Asset) Update `AssetPatch` method, version
2 parents affc2f2 + d0491cd commit c33d4cd

4 files changed

Lines changed: 73 additions & 36 deletions

File tree

UnityPackageImporter/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("dfgHiatus")]
1111
[assembly: AssemblyProduct("UnityPackageImporter")]
12-
[assembly: AssemblyCopyright("Copyright © 2021")]
12+
[assembly: AssemblyCopyright("Copyright © 2025")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.1.3.0")]
35-
[assembly: AssemblyFileVersion("1.1.3.0")]
34+
[assembly: AssemblyVersion("2.3.0.0")]
35+
[assembly: AssemblyFileVersion("2.3.0.0")]

UnityPackageImporter/UnityPackageImporter.cs

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
using Elements.Core;
33
using FrooxEngine;
44
using HarmonyLib;
5-
using Leap.Unity;
65
using ResoniteModLoader;
76
using System.Collections.Generic;
87
using System.IO;
98
using System.Linq;
10-
using System.Security.Policy;
119
using System.Threading.Tasks;
1210
using UnityPackageImporter.Extractor;
1311

@@ -17,7 +15,7 @@ public class UnityPackageImporter : ResoniteMod
1715
{
1816
public override string Name => "UnityPackageImporter";
1917
public override string Author => "dfgHiatus, eia485, delta, Frozenreflex, benaclejames, 989onan";
20-
public override string Version => "2.2.0";
18+
public override string Version => "2.3.0";
2119
public override string Link => "https://github.com/dfgHiatus/ResoniteUnityPackagesImporter";
2220

2321
internal const string UNITY_PACKAGE_EXTENSION = ".unitypackage";
@@ -70,7 +68,7 @@ public override void OnEngineInit()
7068
new Harmony("net.dfgHiatus.UnityPackageImporter").PatchAll();
7169
Config = GetConfiguration();
7270
Directory.CreateDirectory(cachePath);
73-
Engine.Current.RunPostInit(AssetPatch);
71+
Engine.Current.RunPostInit(() => AssetPatch("unitypackage"));
7472
}
7573

7674
public static string[] DecomposeUnityPackage(string file)
@@ -122,10 +120,60 @@ public static string[] DecomposeUnityPackage(string file)
122120
return dirsToImport.ToArray();
123121
}
124122

125-
private static void AssetPatch()
123+
private void AssetPatch(string extension)
126124
{
127-
var aExt = Traverse.Create(typeof(AssetHelper)).Field<Dictionary<AssetClass, List<string>>>("associatedExtensions");
128-
aExt.Value[AssetClass.Model].Add("unitypackage"); // Must not have a "." in the name anywhere!!- @989onan
125+
// Revised implementation using reflection to handle API changes
126+
// same fix as the svg import mod.
127+
try
128+
{
129+
Debug($"Attempting to add {extension} support to import system");
130+
131+
// Get ImportExtension type via reflection since it's now a struct inside AssetHelper
132+
var assHelperType = typeof(AssetHelper);
133+
var importExtType = assHelperType.GetNestedType("ImportExtension",
134+
System.Reflection.BindingFlags.NonPublic);
135+
136+
if (importExtType == null)
137+
{
138+
Error("ImportExtension type not found. This mod is toast.");
139+
return;
140+
}
141+
142+
// Create an ImportExtension instance with reflection
143+
// Constructor args: (string ext, bool autoImport)
144+
var importExt = System.Activator.CreateInstance(importExtType,
145+
new object[] { extension, true });
146+
147+
// Get the associatedExtensions field via reflection
148+
var extensionsField = assHelperType.GetField("associatedExtensions",
149+
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
150+
151+
if (extensionsField == null)
152+
{
153+
Error("Could not find associatedExtensions field");
154+
return;
155+
}
156+
157+
// Get the dictionary and add our extension to the Special asset class
158+
var extensions = extensionsField.GetValue(null);
159+
var dictType = extensions.GetType();
160+
var specialValue = dictType.GetMethod("get_Item").Invoke(extensions, new object[] { AssetClass.Special });
161+
162+
if (specialValue == null)
163+
{
164+
Error("Couldn't get Special asset class list");
165+
return;
166+
}
167+
168+
// Add our ImportExtension to the list
169+
specialValue.GetType().GetMethod("Add").Invoke(specialValue, new[] { importExt });
170+
171+
Debug("{extension} import extension added successfully");
172+
}
173+
catch (System.Exception ex)
174+
{
175+
Error($"Failed to add {extension} to special import formats: {ex}");
176+
}
129177
}
130178

131179
private static async Task Scanfiles(List<string> hasUnityPackage, Slot slot, World world)

UnityPackageImporter/UnityPackageImporter.csproj

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,52 +78,41 @@
7878
</ItemGroup>
7979
<ItemGroup>
8080
<Reference Include="0Harmony">
81-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\rml_libs\0Harmony.dll</HintPath>
81+
<HintPath>..\..\..\SteamLibrary\steamapps\common\Resonite\rml_libs\0Harmony.dll</HintPath>
8282
</Reference>
8383
<Reference Include="Assembly-CSharp">
84-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\Assembly-CSharp.dll</HintPath>
84+
<HintPath>..\..\..\SteamLibrary\steamapps\common\Resonite\Resonite_Data\Managed\Assembly-CSharp.dll</HintPath>
8585
</Reference>
8686
<Reference Include="AssimpNet">
87-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\AssimpNet.dll</HintPath>
87+
<HintPath>..\..\..\SteamLibrary\steamapps\common\Resonite\Resonite_Data\Managed\AssimpNet.dll</HintPath>
8888
</Reference>
8989
<Reference Include="Elements.Assets">
90-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\Elements.Assets.dll</HintPath>
90+
<HintPath>..\..\..\SteamLibrary\steamapps\common\Resonite\Resonite_Data\Managed\Elements.Assets.dll</HintPath>
9191
</Reference>
9292
<Reference Include="Elements.Core">
93-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\Elements.Core.dll</HintPath>
94-
</Reference>
95-
<Reference Include="Elements.Quantity">
96-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\Elements.Quantity.dll</HintPath>
93+
<HintPath>..\..\..\SteamLibrary\steamapps\common\Resonite\Resonite_Data\Managed\Elements.Core.dll</HintPath>
9794
</Reference>
9895
<Reference Include="FrooxEngine">
99-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\FrooxEngine.dll</HintPath>
100-
</Reference>
101-
<Reference Include="FrooxEngine.Commands">
102-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\FrooxEngine.Commands.dll</HintPath>
96+
<HintPath>..\..\..\SteamLibrary\steamapps\common\Resonite\Resonite_Data\Managed\FrooxEngine.dll</HintPath>
10397
</Reference>
10498
<Reference Include="FrooxEngine.Store">
105-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\FrooxEngine.Store.dll</HintPath>
99+
<HintPath>..\..\..\SteamLibrary\steamapps\common\Resonite\Resonite_Data\Managed\FrooxEngine.Store.dll</HintPath>
106100
</Reference>
107101
<Reference Include="ResoniteModLoader">
108-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Libraries\ResoniteModLoader.dll</HintPath>
109-
</Reference>
110-
<Reference Include="SkyFrost.Base">
111-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\SkyFrost.Base.dll</HintPath>
102+
<HintPath>..\..\..\SteamLibrary\steamapps\common\Resonite\Libraries\ResoniteModLoader.dll</HintPath>
112103
</Reference>
113104
<Reference Include="SkyFrost.Base.Models">
114-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\SkyFrost.Base.Models.dll</HintPath>
105+
<HintPath>..\..\..\SteamLibrary\steamapps\common\Resonite\Resonite_Data\Managed\SkyFrost.Base.Models.dll</HintPath>
115106
</Reference>
116107
<Reference Include="System">
117-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\System.dll</HintPath>
118-
</Reference>
119-
<Reference Include="System.Memory">
120-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\System.Memory.dll</HintPath>
108+
<HintPath>..\..\..\SteamLibrary\steamapps\common\Resonite\Resonite_Data\Managed\System.dll</HintPath>
121109
</Reference>
122110
<Reference Include="UnityFrooxEngineRunner">
123-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\Resonite_Data\Managed\UnityFrooxEngineRunner.dll</HintPath>
111+
<HintPath>..\..\..\SteamLibrary\steamapps\common\Resonite\Resonite_Data\Managed\UnityFrooxEngineRunner.dll</HintPath>
124112
</Reference>
125-
<Reference Include="YamlDotNet">
126-
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Resonite\rml_mods\YamlDotNet.dll</HintPath>
113+
<Reference Include="YamlDotNet, Version=16.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e, processorArchitecture=MSIL">
114+
<HintPath>..\packages\YamlDotNet.16.3.0\lib\net47\YamlDotNet.dll</HintPath>
115+
<Private>True</Private>
127116
</Reference>
128117
</ItemGroup>
129118
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Krafs.Publicizer" version="2.2.1" targetFramework="net472" developmentDependency="true" />
4-
<package id="Lib.Harmony" version="2.1.1" targetFramework="net462" />
4+
<package id="YamlDotNet" version="16.3.0" targetFramework="net472" />
55
</packages>

0 commit comments

Comments
 (0)