|
1 | | -# Getting Started |
| 1 | +# Getting Started / 快速开始 |
2 | 2 |
|
3 | | -## Build |
| 3 | +## 1. Inject into APK / 注入 APK |
4 | 4 |
|
5 | | -```bash |
6 | | -cd Android |
7 | | -./gradlew :library:assembleRelease |
8 | | -cd ../StArray.ModManager |
9 | | -dotnet build -c Release |
| 5 | +Download `library-release.aar` from [Releases](https://github.com/StArraySharp/StArray.ModManager/releases). |
| 6 | +从 [Releases](https://github.com/StArraySharp/StArray.ModManager/releases) 下载 `library-release.aar`。 |
| 7 | + |
| 8 | +⚠️ **Add INTERNET permission in `AndroidManifest.xml`** (required for OTA updates & mod networking) |
| 9 | +⚠️ **在 `AndroidManifest.xml` 添加网络权限**(OTA 更新和 Mod 联网需要): |
| 10 | + |
| 11 | +```xml |
| 12 | +<uses-permission android:name="android.permission.INTERNET" /> |
10 | 13 | ``` |
11 | 14 |
|
12 | | -Output: |
13 | | -- `Android/library/build/outputs/aar/library-release.aar` |
14 | | -- `StArray.ModManager/bin/Release/net10.0/StArray.ModManager.dll` |
| 15 | +```bash |
| 16 | +unzip library-release.aar -d aar_content |
| 17 | +apktool d target.apk -o target_src |
| 18 | + |
| 19 | +# Copy .so → lib/ |
| 20 | +cp aar_content/jni/arm64-v8a/*.so target_src/lib/arm64-v8a/ |
| 21 | + |
| 22 | +# Copy CoreCLR runtime DLLs → assets/ |
| 23 | +cp aar_content/assets/runtime/*.dll target_src/assets/ |
15 | 24 |
|
16 | | -## Deploy to Device |
| 25 | +# Decompile classes.jar → smali |
| 26 | +java -jar baksmali.jar d aar_content/classes.jar -o target_src/smali/starray/ |
17 | 27 |
|
| 28 | +# Add to UnityPlayerActivity.onCreate: |
| 29 | +# invoke-static {}, Lstarray/android/modmanager/ModManager;->launch()V |
| 30 | +# |
| 31 | +# ⚠️ launch() defaults to /sdcard/ModManager/. Paths are hardcoded in |
| 32 | +# ModManager.smali. Modify smali constants if your layout differs, |
| 33 | +# or use ModManagerUpdater (configurable paths + OTA auto-update). |
| 34 | +# |
| 35 | +# ⚠️ launch() 默认加载 /sdcard/ModManager/。路径硬编码在 ModManager.smali, |
| 36 | +# 如需自定义请修改 smali 内常量,或使用 ModManagerUpdater。 |
| 37 | + |
| 38 | +# Repack & sign |
| 39 | +apktool b target_src -o repacked.apk |
| 40 | +uber-apk-signer --apks repacked.apk |
18 | 41 | ``` |
19 | | -/sdcard/ModManager/manager/ |
20 | | - StArray.ModManager.dll built managed mod |
21 | | - *.dll deps (ImGui.NET, OpenTK, etc.) |
22 | 42 |
|
23 | | -/sdcard/ModManager/runtime/ |
24 | | - *.dll .NET runtime assemblies |
| 43 | +## 2. Deploy Manager / 部署管理器 |
| 44 | + |
| 45 | +Place manager DLL and dependencies in `/sdcard/ModManager/manager/`. |
| 46 | +将管理器 DLL 及依赖放入 `/sdcard/ModManager/manager/`。 |
| 47 | + |
| 48 | +| File | From / 来源 | |
| 49 | +|---|---| |
| 50 | +| `StArray.ModManager.dll` | [Releases](https://github.com/StArraySharp/StArray.ModManager/releases) → `modmanager.zip` | |
| 51 | +| `ImGui.NET.dll` | Same dir as StArray.ModManager build output | |
| 52 | +| `OpenTK.Graphics.dll` | 同上 | |
| 53 | + |
| 54 | +Final layout / 最终目录: |
| 55 | + |
| 56 | +``` |
| 57 | +/sdcard/ModManager/ |
| 58 | +├── manager/ |
| 59 | +│ ├── StArray.ModManager.dll |
| 60 | +│ ├── ImGui.NET.dll |
| 61 | +│ ├── OpenTK.Graphics.dll |
| 62 | +│ └── modmanager_config.json (auto-generated / 自动生成) |
| 63 | +└── mods/ |
| 64 | + └── {YourModName}/ |
| 65 | + ├── {YourModName}.dll |
| 66 | + └── ... |
25 | 67 | ``` |
26 | 68 |
|
27 | | -Runtime DLLs: [runtime-references release](https://github.com/StArraySharp/StArray.ModManager/releases/tag/0) |
| 69 | +## 3. Write a Mod / 写一个 Mod |
28 | 70 |
|
29 | | -## Inject into APK |
| 71 | +Reference `StArray.ModManager.dll` → implement `IModPlugin` → build DLL → drop into `mods/{ModName}/`. |
| 72 | +引用 `StArray.ModManager.dll` → 实现 `IModPlugin` → 编译 DLL → 放入 `mods/{ModName}/`。 |
30 | 73 |
|
31 | | -```bash |
32 | | -apktool d target.apk -o target_src |
| 74 | +```csharp |
| 75 | +using StArray.ModManager.Runtime; |
| 76 | +using System.Numerics; |
| 77 | +using ImGuiNET; |
| 78 | + |
| 79 | +public class HelloMod : IModPlugin |
| 80 | +{ |
| 81 | + public string Id => "com.example.hello"; |
| 82 | + public string Name => "Hello"; |
| 83 | + public string Version => "1.0.0"; |
| 84 | + public string Author => "you"; |
| 85 | + public string Description => "demo"; |
| 86 | + public IReadOnlyList<string> Dependencies => Array.Empty<string>(); |
| 87 | + |
| 88 | + public void OnLoad() { } |
| 89 | + public void OnUnload() { } |
| 90 | + |
| 91 | + // Draw HUD overlay on game screen / 在游戏画面上叠加 HUD |
| 92 | + public void OnForegroundGUI(ImDrawListPtr drawList) |
| 93 | + { |
| 94 | + drawList.AddText(new Vector2(10, 10), 0xFFFFFFFF, $"FPS: {ImGui.GetIO().Framerate:F0}"); |
| 95 | + } |
| 96 | +} |
33 | 97 | ``` |
34 | 98 |
|
35 | | -Copy `.so` files to `target_src/lib/arm64-v8a/`: |
36 | | -- From AAR: `libmodmanager.so`, `libmonodroid.so`, `libcimgui.so` |
37 | | -- CoreCLR: `libcoreclr.so`, `libclrjit.so`, `libSystem.Native.so`, etc. |
| 99 | +### Optional interfaces / 可选接口 |
38 | 100 |
|
39 | | -Add to `UnityPlayerActivity.smali` onCreate: |
| 101 | +```csharp |
| 102 | +interface IModSettings { void OnGui(); } // Custom settings tab / 自定义设置页 |
| 103 | +interface IModSettingCustomDraw { void DrawInspector(); } // Custom inspector / 自定义检查器 |
| 104 | +``` |
| 105 | + |
| 106 | +### Field attributes / 设置特性 |
| 107 | + |
| 108 | +```csharp |
| 109 | +[ModSettingLabel("Health Multiplier / 血量倍率")] |
| 110 | +[ModSettingRange(0.1f, 10f)] |
| 111 | +public float HealthMultiplier = 1f; |
40 | 112 |
|
41 | | -```smali |
42 | | -invoke-static {}, Lstarray/android/modmanager/ModManager;->launch()V |
| 113 | +[ModSettingLabelSide(ModInspector.LabelSide.Left)] |
| 114 | +[ModSettingJson(Lines = 10)] |
| 115 | +public string JsonConfig = "{}"; |
43 | 116 | ``` |
44 | 117 |
|
45 | | -Add `smali/starray/android/modmanager/ModManager.smali` and `ModManager$1.smali` from the AAR. |
| 118 | +### Overlay drawing / Overlay 绘制 |
46 | 119 |
|
47 | | -```bash |
48 | | -apktool b target_src -o repacked.apk |
49 | | -uber-apk-signer --apks repacked.apk |
| 120 | +```csharp |
| 121 | +void OnBackgroundGUI(ImDrawListPtr d) { } // Behind ImGui windows / 窗口下方 (watermark / 水印) |
| 122 | +void OnForegroundGUI(ImDrawListPtr d) { } // Above ImGui windows / 窗口上方 (HUD) |
50 | 123 | ``` |
0 commit comments