Skip to content

Commit 5982e8c

Browse files
committed
feat: add entryAssembly/entryMethod to version.json for Android updater
- Add entryAssembly and entryMethod fields to VersionInfo in ModManagerUpdater.java - Update launch() to read .NET entry point config from version.json, falling back to defaults - Update root version.json with entryAssembly: "StArray.ModManager.dll" and entryMethod: "StArray.ModManager.Managed::Entry"
1 parent fbc2b0f commit 5982e8c

44 files changed

Lines changed: 2391 additions & 656 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ project.lock.json
4242
# Rider
4343
**/rider.project.restore.info
4444

45-
# Unity test project (exclude entire dir)
45+
# test project (exclude entire dir)
4646
TestAndroidProject/
4747
TestAndroidProject2/
48+
dx12app/
4849

4950
# Runtime data (mods, etc — user-managed)
5051
/Runtime/

‎Android/library/src/main/java/starray/android/modmanager/ModManagerUpdater.java‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,41 @@ private void launch(Path mgr, Path rt, Path mods, boolean useNewThread) {
288288
Files.createDirectories(mods);
289289
Log.i(TAG, "Created mods directory: " + mods);
290290
}
291+
292+
// 从 version.json 读取入口配置,不存在则用默认值
293+
var verFile = mgr.resolve("version.json");
294+
String dll = "StArray.ModManager.dll";
295+
String type = "StArray.ModManager.Managed";
296+
String method = "Entry";
297+
if (Files.exists(verFile)) {
298+
try {
299+
var localVer = JSON.parseObject(
300+
new String(Files.readAllBytes(verFile)), VersionInfo.class);
301+
if (localVer.entryAssembly != null && !localVer.entryAssembly.isEmpty())
302+
dll = localVer.entryAssembly;
303+
if (localVer.entryMethod != null && !localVer.entryMethod.isEmpty()) {
304+
// 格式:"TypeName::MethodName" → type, method
305+
var parts = localVer.entryMethod.split("::", 2);
306+
if (parts.length == 2) {
307+
type = parts[0].trim();
308+
method = parts[1].trim();
309+
} else {
310+
// 单值当作方法名,类型取默认
311+
method = localVer.entryMethod.trim();
312+
}
313+
}
314+
Log.i(TAG, "Entry from version.json: " + dll + " → " + type + "::" + method);
315+
} catch (Exception e) {
316+
Log.w(TAG, "Failed to parse version.json for entry config, using defaults", e);
317+
}
318+
} else {
319+
Log.i(TAG, "No version.json, using default entry: " + dll + " → " + type + "::" + method);
320+
}
321+
291322
new ModManager()
292323
.dotnetRoot(rt.toString())
293324
.addAssemblyDir(mgr.toAbsolutePath().toString())
294-
.start("StArray.ModManager.dll",
295-
"StArray.ModManager.Managed", "Entry",
296-
mods.toAbsolutePath().toString());
325+
.start(dll, type, method, mods.toAbsolutePath().toString());
297326
Log.i(TAG, "ModManager started");
298327
} catch (IOException e) {
299328
Log.e(TAG, "Failed to create mods directory: " + e.getMessage(), e);
@@ -324,6 +353,12 @@ public static class VersionInfo {
324353
public String managerUrl;
325354
@JSONField(name = "sha256")
326355
public String sha256;
356+
/** 入口程序集文件名(如 "StArray.ModManager.dll") */
357+
@JSONField(name = "entryAssembly")
358+
public String entryAssembly;
359+
/** 入口类型与方法(如 "StArray.ModManager.Managed::Entry") */
360+
@JSONField(name = "entryMethod")
361+
public String entryMethod;
327362
}
328363

329364
// ──── HTTP ────
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static int Entry(int argc, IntPtr argv)
7575
Logger.Error($"{nameof(Managed)}-Benchmark", $"ModLoader init: {Benchmark.End():F3}s");
7676

7777
Benchmark.Begin();
78-
var ui = new ModManagerUI(loader);
78+
var ui = new ModManagerUI(loader, Path.GetDirectoryName(AssemblyPath)!);
7979
Logger.Error($"{nameof(Managed)}-Benchmark", $"ModManagerUI init: {Benchmark.End():F3}s");
8080

8181
Benchmark.Begin();
File renamed without changes.
File renamed without changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Runtime.InteropServices;
2+
using StArray.ModManager.Runtime;
3+
4+
namespace StArray.ModManager.Native;
5+
6+
public class DobbyHook : IHook
7+
{
8+
public nint Hook(nint target, nint detour)
9+
{
10+
if (Dobby.Hook(target, detour, out var origin) != 0)
11+
return nint.Zero;
12+
return origin;
13+
}
14+
15+
public bool Unhook(nint target)
16+
{
17+
return Dobby.Destroy(target) == 0;
18+
}
19+
20+
public nint GetFunction(string library, string name)
21+
{
22+
return Dobby.SymbolResolver(library, name);
23+
}
24+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)