Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 428b322

Browse files
Merge pull request #39 from Next-Fast/develop
Develop 重构
2 parents b74f2fd + 93424b6 commit 428b322

File tree

286 files changed

+5221
-4911
lines changed

Some content is hidden

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

286 files changed

+5221
-4911
lines changed

.github/workflows/Build-Release.yml

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build-Release
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
if: ${{ github.repository_owner == 'TheIdealShipAU' }}
12+
steps:
13+
- uses: actions/cache@v2
14+
with:
15+
path: |
16+
~/.nuget/packages
17+
~/.cache/bepinex
18+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
19+
restore-keys: |
20+
${{ runner.os }}-nuget-
21+
22+
- uses: actions/checkout@v2
23+
with:
24+
submodules: true
25+
26+
- name: Collect build info
27+
id: info
28+
uses: actions/github-script@v6
29+
with:
30+
script: |
31+
let version = "1.0.0";
32+
core.setOutput(ReleaseVersion, version);
33+
34+
- name: install wget
35+
run: sudo apt install wget
36+
37+
- name: download BepInEx
38+
run: wget https://builds.bepinex.dev/projects/bepinex_be/672/BepInEx-Unity.IL2CPP-win-x86-6.0.0-be.672%2B472e950.zip
39+
40+
- name: BepInEx
41+
run: unzip BepInEx-Unity.IL2CPP-win-x86-6.0.0-be.672+422e950.zip -d ./NextShipRelease/
42+
43+
- name: Setup .NET
44+
uses: actions/setup-dotnet@v1
45+
with:
46+
dotnet-version: 8.x
47+
48+
- name: build
49+
run: dotnet build NextShip/NextShip.csproj --configuration Release
50+
51+
- name: path
52+
run: sudo chmod -R 777 ./NextShipRelease
53+
54+
- name: upload NextShip
55+
uses: actions/upload-artifact@v3
56+
with:
57+
name: NextShip.dll
58+
path: NextShip/bin/Release/net8.0/NextShip.dll
59+
60+
- name: upload TheIdealShip
61+
uses: actions/upload-artifact@v3
62+
with:
63+
name: NextShip
64+
path: ./NextShipRelease

NSLangAnalyzer/Constants.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
global using static NSLangAnalyzer.Constants;
2+
3+
namespace NSLangAnalyzer;
4+
5+
public static class Constants
6+
{
7+
public const string FileSuffix = "NS";
8+
9+
public const string FileSuffix2 = "NSL";
10+
11+
public const string FileSuffix3 = "ns";
12+
13+
public const string FileSuffix4 = "nsl";
14+
}

NSLangAnalyzer/FileFinder.cs

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
namespace NSLangAnalyzer;
2+
3+
internal class FileFinder
4+
{
5+
private static readonly string[] Extensions = [FileSuffix, FileSuffix2, FileSuffix3, FileSuffix4];
6+
private readonly List<FileInfo> _fileInfos = [];
7+
private readonly List<ReadInfo> _readInfos = [];
8+
9+
public FileFinder ReadFiles()
10+
{
11+
if (_fileInfos.Count == 0) throw new NSLException("FileInfo = 0");
12+
13+
foreach (var info in _fileInfos)
14+
{
15+
using var readStream = info.OpenRead();
16+
using var reader = new StreamReader(readStream);
17+
var strings = string.Empty;
18+
19+
var OneLine = reader.ReadLine();
20+
if (OneLine == null || !OneLine.StartsWith('[') || !OneLine.EndsWith(']')) continue;
21+
22+
var texts = OneLine
23+
.Replace("[", string.Empty)
24+
.Replace("]", string.Empty)
25+
.Split(":");
26+
27+
var name = texts[0];
28+
var author = texts[1];
29+
30+
var line = reader.ReadLine();
31+
while (line != null)
32+
{
33+
strings += line;
34+
line = reader.ReadLine();
35+
}
36+
37+
_readInfos.Add(new ReadInfo
38+
{
39+
Info = info,
40+
ReadStrings = strings,
41+
name = name,
42+
author = author
43+
});
44+
}
45+
46+
return this;
47+
}
48+
49+
public FileFinder Get(DirectoryInfo directory)
50+
{
51+
_readInfos.Clear();
52+
_fileInfos.AddRange(directory.GetFiles().Where(isFile));
53+
return this;
54+
}
55+
56+
private static bool isFile(FileInfo fileInfo)
57+
{
58+
return Extensions.Any(varExtension => fileInfo.Extension == "." + varExtension);
59+
}
60+
61+
private class ReadInfo
62+
{
63+
public string? ReadStrings { get; set; }
64+
65+
public FileInfo? Info { get; set; }
66+
67+
public string? name { get; set; }
68+
69+
public string? author { get; set; }
70+
}
71+
}

NSLangAnalyzer/MainAnalyzer.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace NSLangAnalyzer;
2+
3+
public class MainAnalyzer
4+
{
5+
private readonly FileFinder _Finder = new();
6+
7+
public void Find(string path)
8+
{
9+
if (!Directory.Exists(path))
10+
throw new NSLException("不存在指定文件夹");
11+
12+
var finder = _Finder.Get(new DirectoryInfo(path)).ReadFiles();
13+
}
14+
}

NSLangAnalyzer/NSLException.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace NSLangAnalyzer;
2+
3+
public class NSLException : Exception
4+
{
5+
public NSLException()
6+
{
7+
}
8+
9+
public NSLException(string message) : base(message)
10+
{
11+
}
12+
13+
public NSLException(string message, Exception exception) : base(message, exception)
14+
{
15+
}
16+
}

NSLangAnalyzer/NSLangAnalyzer.csproj

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

NextShip.Api/APIHarmony.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using HarmonyLib;
2+
3+
namespace NextShip.Api;
4+
5+
internal static class APIHarmony
6+
{
7+
static APIHarmony()
8+
{
9+
_Harmony = new Harmony("net.NextShip.Api");
10+
}
11+
12+
internal static Harmony _Harmony { get; set; }
13+
}

NextShip.Api/APIReadme.md

Whitespace-only changes.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Reflection;
2+
using NextShip.Api.Interfaces;
3+
4+
namespace NextShip.Api.Attributes;
5+
6+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Constructor)]
7+
[MeansImplicitUse]
8+
public class FastAddRole : Attribute
9+
{
10+
public static void Registration(IRoleManager _roleManager, Assembly assembly)
11+
{
12+
var Types = assembly.GetTypes();
13+
14+
foreach (var VarType in Types.Where(n => n.Is<FastAddRole>() && n.GetInterface(nameof(IRole)) != null))
15+
{
16+
var constructorInfos = VarType.GetConstructors().Where(n => n.Is<FastAddRole>());
17+
foreach (var variableConstructorInfo in constructorInfos)
18+
_roleManager.Register(variableConstructorInfo.Invoke(null, null) as IRole);
19+
}
20+
}
21+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace NextShip.Api.Attributes;
2+
3+
[MeansImplicitUse]
4+
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
5+
public class FastReadAdd(byte callId) : Attribute
6+
{
7+
public readonly byte CallId = callId;
8+
}

NextShip.Api/Utilities/Attributes/Il2CppRegisterAttribute.cs NextShip.Api/Attributes/Il2CppRegisterAttribute.cs

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
1+
#nullable enable
12
using System.Reflection;
23
using HarmonyLib;
34
using Il2CppInterop.Runtime.Injection;
45

5-
namespace NextShip.Api.Utilities.Attributes;
6+
namespace NextShip.Api.Attributes;
67

78
[AttributeUsage(AttributeTargets.Class)]
8-
public sealed class Il2CppRegisterAttribute : Attribute
9+
public sealed class Il2CppRegisterAttribute(params Type[] interfaces) : Attribute
910
{
10-
public Il2CppRegisterAttribute(params Type[] interfaces)
11+
public Il2CppRegisterAttribute() : this(Type.EmptyTypes)
1112
{
12-
Interfaces = interfaces;
1313
}
1414

15-
public Il2CppRegisterAttribute()
16-
{
17-
Interfaces = Type.EmptyTypes;
18-
}
1915

20-
public Type[] Interfaces { get; }
16+
public Type[] Interfaces { get; } = interfaces;
2117

22-
public static void Registration(Type type)
18+
public static void Registration(Type? type)
2319
{
2420
Info("Start Registration", "Il2CppRegister");
2521

2622
var attribute =
27-
type.GetCustomAttribute<Il2CppRegisterAttribute>();
23+
type?.GetCustomAttribute<Il2CppRegisterAttribute>();
24+
2825
if (attribute != null) registrationForTarget(type, attribute.Interfaces);
2926

3027
Info("Complete Registration", "Il2CppRegister");
3128
}
3229

33-
private static void registrationForTarget(Type targetType, Type[] interfaces)
30+
private static void registrationForTarget(Type? targetType, Type[] interfaces)
3431
{
35-
var targetBase = targetType.BaseType;
32+
var targetBase = targetType?.BaseType;
3633

37-
Il2CppRegisterAttribute baseAttribute = null;
34+
Il2CppRegisterAttribute? baseAttribute = null;
3835

39-
if (targetBase != null) baseAttribute = targetBase.GetCustomAttribute<Il2CppRegisterAttribute>();
36+
if (targetBase != null)
37+
baseAttribute = targetBase.GetCustomAttribute<Il2CppRegisterAttribute>();
4038

41-
if (baseAttribute != null) registrationForTarget(targetBase, baseAttribute.Interfaces);
39+
if (baseAttribute != null)
40+
registrationForTarget(targetBase, baseAttribute.Interfaces);
4241

4342
Debug($"Registration {targetType}", "Register");
4443

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System.Collections;
2+
using System.Reflection;
3+
4+
namespace NextShip.Api.Attributes;
5+
6+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor)]
7+
public sealed class LoadAttribute(LoadMode mode = LoadMode.Load) : Attribute
8+
{
9+
public static readonly List<LoadAttribute> Loads = [];
10+
11+
public static string[] MethodNames = EnumHelper.GetAllNames<LoadMode>();
12+
13+
public IEnumerator Enumerator;
14+
public LoadMode Mode = mode;
15+
16+
public static void Registration(Type type)
17+
{
18+
Info("Start Registration", filename: MethodUtils.GetClassName());
19+
20+
if (type.GetCustomAttribute<LoadAttribute>() == null) return;
21+
22+
ConstructorInfo constructor;
23+
if (
24+
(
25+
constructor = type.GetConstructor
26+
(
27+
BindingFlags.Public |
28+
BindingFlags.Static |
29+
BindingFlags.NonPublic,
30+
Array.Empty<Type>()
31+
)
32+
)
33+
!= null && constructor.Is<LoadAttribute>())
34+
constructor.Invoke(null, null);
35+
36+
foreach (var MethodInfo in type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public))
37+
{
38+
if (MethodInfo.ReturnType != typeof(IEnumerator))
39+
continue;
40+
41+
var load = MethodInfo.GetCustomAttribute<LoadAttribute>();
42+
LoadMode? mode = null;
43+
if (Enum.TryParse(MethodInfo.Name, out LoadMode OutMode))
44+
mode = OutMode;
45+
46+
if (load != null)
47+
{
48+
load.Enumerator = MethodInfo.Invoke(null, null) as IEnumerator;
49+
Loads.Add(load);
50+
continue;
51+
}
52+
53+
if (mode != null)
54+
Loads.Add(new LoadAttribute
55+
{
56+
Mode = (LoadMode)mode,
57+
Enumerator = MethodInfo.Invoke(null, null) as IEnumerator
58+
});
59+
}
60+
61+
Info($"Statically Initialized Class {type}", "LoadAttribute");
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Reflection;
2+
using NextShip.Api.Interfaces;
3+
4+
namespace NextShip.Api.Attributes;
5+
6+
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
7+
public sealed class NextEventListener : Attribute
8+
{
9+
public static void RegisterFormAssembly(Assembly assembly, IEventManager manager)
10+
{
11+
}
12+
13+
public static void RegisterFormService(IServiceProvider provider, IEventManager manager)
14+
{
15+
}
16+
}

0 commit comments

Comments
 (0)