1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-11 07:23:28 +08:00

move resources to embedded

This commit is contained in:
2024-09-02 18:17:53 +08:00
parent 19a050639d
commit bacd1b7d75
27 changed files with 52 additions and 13 deletions

View File

@@ -6,9 +6,23 @@ namespace UXAssist.Common;
public static class Util public static class Util
{ {
public static byte[] LoadEmbeddedResource(string path, Assembly assembly = null)
{
if (assembly == null)
{
assembly = Assembly.GetCallingAssembly();
}
var info = assembly.GetName();
var name = info.Name;
using var stream = assembly.GetManifestResourceStream($"{name}.{path.Replace('/', '.')}")!;
var buffer = new byte[stream.Length];
_ = stream.Read(buffer, 0, buffer.Length);
return buffer;
}
public static Texture2D LoadTexture(string path) public static Texture2D LoadTexture(string path)
{ {
var fileData = System.IO.File.ReadAllBytes(path); var fileData = File.ReadAllBytes(path);
var tex = new Texture2D(2, 2); var tex = new Texture2D(2, 2);
tex.LoadImage(fileData); tex.LoadImage(fileData);
return tex; return tex;
@@ -20,5 +34,19 @@ public static class Util
return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f)); return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
} }
public static string PluginFolder => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); public static Texture2D LoadEmbeddedTexture(string path, Assembly assembly = null)
{
var fileData = LoadEmbeddedResource(path, assembly);
var tex = new Texture2D(2, 2);
tex.LoadImage(fileData);
return tex;
}
public static Sprite LoadEmbeddedSprite(string path, Assembly assembly = null)
{
var tex = LoadEmbeddedTexture(path, assembly);
return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
}
public static string PluginFolder(Assembly assembly = null) => Path.GetDirectoryName((assembly == null ? Assembly.GetCallingAssembly() : assembly).Location);
} }

View File

@@ -1637,7 +1637,7 @@ public static class FactoryPatch
private static void AddBeltSignalProtos() private static void AddBeltSignalProtos()
{ {
if (!_initialized || _loaded) return; if (!_initialized || _loaded) return;
var pluginfolder = Util.PluginFolder; var assembly = Assembly.GetExecutingAssembly();
var signals = LDB._signals; var signals = LDB._signals;
SignalProto[] protos = SignalProto[] protos =
[ [
@@ -1647,7 +1647,7 @@ public static class FactoryPatch
Name = "存储单元", Name = "存储单元",
GridIndex = 3601, GridIndex = 3601,
IconPath = "assets/signal/memory.png", IconPath = "assets/signal/memory.png",
_iconSprite = Util.LoadSprite($"{pluginfolder}/assets/signal/memory.png"), _iconSprite = Util.LoadEmbeddedSprite($"assets/signal/memory.png", assembly),
SID = "" SID = ""
}, },
new SignalProto new SignalProto
@@ -1656,7 +1656,7 @@ public static class FactoryPatch
Name = "能量碎片", Name = "能量碎片",
GridIndex = 3602, GridIndex = 3602,
IconPath = "assets/signal/energy-fragment.png", IconPath = "assets/signal/energy-fragment.png",
_iconSprite = Util.LoadSprite($"{pluginfolder}/assets/signal/energy-fragment.png"), _iconSprite = Util.LoadEmbeddedSprite($"assets/signal/energy-fragment.png", assembly),
SID = "" SID = ""
}, },
new SignalProto new SignalProto
@@ -1665,7 +1665,7 @@ public static class FactoryPatch
Name = "硅基神经元", Name = "硅基神经元",
GridIndex = 3603, GridIndex = 3603,
IconPath = "assets/signal/silicon-neuron.png", IconPath = "assets/signal/silicon-neuron.png",
_iconSprite = Util.LoadSprite($"{pluginfolder}/assets/signal/silicon-neuron.png"), _iconSprite = Util.LoadEmbeddedSprite($"assets/signal/silicon-neuron.png", assembly),
SID = "" SID = ""
}, },
new SignalProto new SignalProto
@@ -1674,7 +1674,7 @@ public static class FactoryPatch
Name = "负熵奇点", Name = "负熵奇点",
GridIndex = 3604, GridIndex = 3604,
IconPath = "assets/signal/negentropy.png", IconPath = "assets/signal/negentropy.png",
_iconSprite = Util.LoadSprite($"{pluginfolder}/assets/signal/negentropy.png"), _iconSprite = Util.LoadEmbeddedSprite($"assets/signal/negentropy.png", assembly),
SID = "" SID = ""
}, },
new SignalProto new SignalProto
@@ -1683,7 +1683,7 @@ public static class FactoryPatch
Name = "物质重组器", Name = "物质重组器",
GridIndex = 3605, GridIndex = 3605,
IconPath = "assets/signal/reassembler.png", IconPath = "assets/signal/reassembler.png",
_iconSprite = Util.LoadSprite($"{pluginfolder}/assets/signal/reassembler.png"), _iconSprite = Util.LoadEmbeddedSprite($"assets/signal/reassembler.png", assembly),
SID = "" SID = ""
}, },
new SignalProto new SignalProto
@@ -1692,7 +1692,7 @@ public static class FactoryPatch
Name = "虚粒子", Name = "虚粒子",
GridIndex = 3606, GridIndex = 3606,
IconPath = "assets/signal/virtual-particle.png", IconPath = "assets/signal/virtual-particle.png",
_iconSprite = Util.LoadSprite($"{pluginfolder}/assets/signal/virtual-particle.png"), _iconSprite = Util.LoadEmbeddedSprite($"assets/signal/virtual-particle.png", assembly),
SID = "" SID = ""
}, },
]; ];

View File

@@ -525,7 +525,8 @@ public static class GamePatch
private static IEnumerable<CodeInstruction> UICursor_LoadCursors_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) private static IEnumerable<CodeInstruction> UICursor_LoadCursors_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{ {
var matcher = new CodeMatcher(instructions, generator); var matcher = new CodeMatcher(instructions, generator);
matcher.Start().MatchForward(false, /*
matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldc_I4_S), new CodeMatch(OpCodes.Ldc_I4_S),
new CodeMatch(OpCodes.Newarr) new CodeMatch(OpCodes.Newarr)
); );
@@ -561,6 +562,7 @@ public static class GamePatch
]; ];
}) })
); );
*/
matcher.MatchForward(false, matcher.MatchForward(false,
new CodeMatch(OpCodes.Stsfld, AccessTools.Field(typeof(UICursor), nameof(UICursor.cursorHots))), new CodeMatch(OpCodes.Stsfld, AccessTools.Field(typeof(UICursor), nameof(UICursor.cursorHots))),
new CodeMatch(OpCodes.Ldc_I4_1), new CodeMatch(OpCodes.Ldc_I4_1),
@@ -576,7 +578,7 @@ public static class GamePatch
var newWidth = 32 * multiplier; var newWidth = 32 * multiplier;
var newHeight = 32 * multiplier; var newHeight = 32 * multiplier;
if (cursor.width == newWidth && cursor.height == newHeight) continue; if (cursor.width == newWidth && cursor.height == newHeight) continue;
UICursor.cursorTexs[i] = ResizeTexture2D(cursor, 32 * multiplier, 32 * multiplier); UICursor.cursorTexs[i] = ResizeTexture2D(cursor, newWidth, newHeight);
} }
if (multiplier <= 1) return; if (multiplier <= 1) return;
@@ -603,6 +605,7 @@ public static class GamePatch
rt.ResolveAntiAliasedSurface(); rt.ResolveAntiAliasedSurface();
var result = new Texture2D(targetWidth, targetHeight, texture2D.format, false); var result = new Texture2D(targetWidth, targetHeight, texture2D.format, false);
result.ReadPixels(new Rect(0, 0, targetWidth, targetHeight), 0, 0); result.ReadPixels(new Rect(0, 0, targetWidth, targetHeight), 0, 0);
result.filterMode = FilterMode.Trilinear;
result.Apply(); result.Apply();
RenderTexture.active = oldActive; RenderTexture.active = oldActive;
rt.Release(); rt.Release();

View File

@@ -20,12 +20,20 @@
<PackageReference Include="DysonSphereProgram.Modding.CommonAPI" Version="1.6.5" /> <PackageReference Include="DysonSphereProgram.Modding.CommonAPI" Version="1.6.5" />
<PackageReference Include="DysonSphereProgram.Modding.DSPModSave" Version="1.2" /> <PackageReference Include="DysonSphereProgram.Modding.DSPModSave" Version="1.2" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="assets/signal/energy-fragment.png" />
<EmbeddedResource Include="assets/signal/memory.png" />
<EmbeddedResource Include="assets/signal/negentropy.png" />
<EmbeddedResource Include="assets/signal/reassembler.png" />
<EmbeddedResource Include="assets/signal/silicon-neuron.png" />
<EmbeddedResource Include="assets/signal/virtual-particle.png" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'"> <ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" /> <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Release'"> <Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Release'">
<Exec Command="del /F /Q package\$(ProjectName)-$(Version).zip&#xA;copy /y &quot;$(TargetPath)&quot; package\plugins\&#xA;powershell Compress-Archive -Force -DestinationPath 'package/$(ProjectName)-$(Version).zip' -Path package/plugins, package/icon.png, package/manifest.json, README.md, CHANGELOG.md" /> <Exec Command="del /F /Q package\$(ProjectName)-$(Version).zip&#xA;powershell Compress-Archive -Force -DestinationPath 'package/$(ProjectName)-$(Version).zip' -Path &quot;$(TargetPath)&quot;, package/icon.png, package/manifest.json, README.md, CHANGELOG.md" />
</Target> </Target>
</Project> </Project>

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 154 B

After

Width:  |  Height:  |  Size: 154 B

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB