Skip to content

Commit

Permalink
Merge pull request #39 from Next-Fast/develop
Browse files Browse the repository at this point in the history
Develop 重构
  • Loading branch information
TianMengLucky authored Jul 2, 2024
2 parents b74f2fd + 93424b6 commit 428b322
Show file tree
Hide file tree
Showing 286 changed files with 5,221 additions and 4,911 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/Build-Release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build-Release

on:
push:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest

if: ${{ github.repository_owner == 'TheIdealShipAU' }}
steps:
- uses: actions/cache@v2
with:
path: |
~/.nuget/packages
~/.cache/bepinex
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- uses: actions/checkout@v2
with:
submodules: true

- name: Collect build info
id: info
uses: actions/github-script@v6
with:
script: |
let version = "1.0.0";
core.setOutput(ReleaseVersion, version);
- name: install wget
run: sudo apt install wget

- name: download BepInEx
run: wget https://builds.bepinex.dev/projects/bepinex_be/672/BepInEx-Unity.IL2CPP-win-x86-6.0.0-be.672%2B472e950.zip

- name: BepInEx
run: unzip BepInEx-Unity.IL2CPP-win-x86-6.0.0-be.672+422e950.zip -d ./NextShipRelease/

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.x

- name: build
run: dotnet build NextShip/NextShip.csproj --configuration Release

- name: path
run: sudo chmod -R 777 ./NextShipRelease

- name: upload NextShip
uses: actions/upload-artifact@v3
with:
name: NextShip.dll
path: NextShip/bin/Release/net8.0/NextShip.dll

- name: upload TheIdealShip
uses: actions/upload-artifact@v3
with:
name: NextShip
path: ./NextShipRelease
14 changes: 14 additions & 0 deletions NSLangAnalyzer/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
global using static NSLangAnalyzer.Constants;

namespace NSLangAnalyzer;

public static class Constants
{
public const string FileSuffix = "NS";

public const string FileSuffix2 = "NSL";

public const string FileSuffix3 = "ns";

public const string FileSuffix4 = "nsl";
}
71 changes: 71 additions & 0 deletions NSLangAnalyzer/FileFinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
namespace NSLangAnalyzer;

internal class FileFinder
{
private static readonly string[] Extensions = [FileSuffix, FileSuffix2, FileSuffix3, FileSuffix4];
private readonly List<FileInfo> _fileInfos = [];
private readonly List<ReadInfo> _readInfos = [];

public FileFinder ReadFiles()
{
if (_fileInfos.Count == 0) throw new NSLException("FileInfo = 0");

foreach (var info in _fileInfos)
{
using var readStream = info.OpenRead();
using var reader = new StreamReader(readStream);
var strings = string.Empty;

var OneLine = reader.ReadLine();
if (OneLine == null || !OneLine.StartsWith('[') || !OneLine.EndsWith(']')) continue;

var texts = OneLine
.Replace("[", string.Empty)
.Replace("]", string.Empty)
.Split(":");

var name = texts[0];
var author = texts[1];

var line = reader.ReadLine();
while (line != null)
{
strings += line;
line = reader.ReadLine();
}

_readInfos.Add(new ReadInfo
{
Info = info,
ReadStrings = strings,
name = name,
author = author
});
}

return this;
}

public FileFinder Get(DirectoryInfo directory)
{
_readInfos.Clear();
_fileInfos.AddRange(directory.GetFiles().Where(isFile));
return this;
}

private static bool isFile(FileInfo fileInfo)
{
return Extensions.Any(varExtension => fileInfo.Extension == "." + varExtension);
}

private class ReadInfo
{
public string? ReadStrings { get; set; }

public FileInfo? Info { get; set; }

public string? name { get; set; }

public string? author { get; set; }
}
}
14 changes: 14 additions & 0 deletions NSLangAnalyzer/MainAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace NSLangAnalyzer;

public class MainAnalyzer
{
private readonly FileFinder _Finder = new();

public void Find(string path)
{
if (!Directory.Exists(path))
throw new NSLException("不存在指定文件夹");

var finder = _Finder.Get(new DirectoryInfo(path)).ReadFiles();
}
}
16 changes: 16 additions & 0 deletions NSLangAnalyzer/NSLException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace NSLangAnalyzer;

public class NSLException : Exception
{
public NSLException()
{
}

public NSLException(string message) : base(message)
{
}

public NSLException(string message, Exception exception) : base(message, exception)
{
}
}
9 changes: 9 additions & 0 deletions NSLangAnalyzer/NSLangAnalyzer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
13 changes: 13 additions & 0 deletions NextShip.Api/APIHarmony.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using HarmonyLib;

namespace NextShip.Api;

internal static class APIHarmony
{
static APIHarmony()
{
_Harmony = new Harmony("net.NextShip.Api");
}

internal static Harmony _Harmony { get; set; }
}
Empty file removed NextShip.Api/APIReadme.md
Empty file.
21 changes: 21 additions & 0 deletions NextShip.Api/Attributes/FastAddRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Reflection;
using NextShip.Api.Interfaces;

namespace NextShip.Api.Attributes;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Constructor)]
[MeansImplicitUse]
public class FastAddRole : Attribute
{
public static void Registration(IRoleManager _roleManager, Assembly assembly)
{
var Types = assembly.GetTypes();

foreach (var VarType in Types.Where(n => n.Is<FastAddRole>() && n.GetInterface(nameof(IRole)) != null))
{
var constructorInfos = VarType.GetConstructors().Where(n => n.Is<FastAddRole>());
foreach (var variableConstructorInfo in constructorInfos)
_roleManager.Register(variableConstructorInfo.Invoke(null, null) as IRole);
}
}
}
8 changes: 8 additions & 0 deletions NextShip.Api/Attributes/FastReadAdd.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace NextShip.Api.Attributes;

[MeansImplicitUse]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class FastReadAdd(byte callId) : Attribute
{
public readonly byte CallId = callId;
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
#nullable enable
using System.Reflection;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;

namespace NextShip.Api.Utilities.Attributes;
namespace NextShip.Api.Attributes;

[AttributeUsage(AttributeTargets.Class)]
public sealed class Il2CppRegisterAttribute : Attribute
public sealed class Il2CppRegisterAttribute(params Type[] interfaces) : Attribute
{
public Il2CppRegisterAttribute(params Type[] interfaces)
public Il2CppRegisterAttribute() : this(Type.EmptyTypes)
{
Interfaces = interfaces;
}

public Il2CppRegisterAttribute()
{
Interfaces = Type.EmptyTypes;
}

public Type[] Interfaces { get; }
public Type[] Interfaces { get; } = interfaces;

public static void Registration(Type type)
public static void Registration(Type? type)
{
Info("Start Registration", "Il2CppRegister");

var attribute =
type.GetCustomAttribute<Il2CppRegisterAttribute>();
type?.GetCustomAttribute<Il2CppRegisterAttribute>();

if (attribute != null) registrationForTarget(type, attribute.Interfaces);

Info("Complete Registration", "Il2CppRegister");
}

private static void registrationForTarget(Type targetType, Type[] interfaces)
private static void registrationForTarget(Type? targetType, Type[] interfaces)
{
var targetBase = targetType.BaseType;
var targetBase = targetType?.BaseType;

Il2CppRegisterAttribute baseAttribute = null;
Il2CppRegisterAttribute? baseAttribute = null;

if (targetBase != null) baseAttribute = targetBase.GetCustomAttribute<Il2CppRegisterAttribute>();
if (targetBase != null)
baseAttribute = targetBase.GetCustomAttribute<Il2CppRegisterAttribute>();

if (baseAttribute != null) registrationForTarget(targetBase, baseAttribute.Interfaces);
if (baseAttribute != null)
registrationForTarget(targetBase, baseAttribute.Interfaces);

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

Expand Down
63 changes: 63 additions & 0 deletions NextShip.Api/Attributes/LoadAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Collections;
using System.Reflection;

namespace NextShip.Api.Attributes;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor)]
public sealed class LoadAttribute(LoadMode mode = LoadMode.Load) : Attribute
{
public static readonly List<LoadAttribute> Loads = [];

public static string[] MethodNames = EnumHelper.GetAllNames<LoadMode>();

public IEnumerator Enumerator;
public LoadMode Mode = mode;

public static void Registration(Type type)
{
Info("Start Registration", filename: MethodUtils.GetClassName());

if (type.GetCustomAttribute<LoadAttribute>() == null) return;

ConstructorInfo constructor;
if (
(
constructor = type.GetConstructor
(
BindingFlags.Public |
BindingFlags.Static |
BindingFlags.NonPublic,
Array.Empty<Type>()
)
)
!= null && constructor.Is<LoadAttribute>())
constructor.Invoke(null, null);

foreach (var MethodInfo in type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public))
{
if (MethodInfo.ReturnType != typeof(IEnumerator))
continue;

var load = MethodInfo.GetCustomAttribute<LoadAttribute>();
LoadMode? mode = null;
if (Enum.TryParse(MethodInfo.Name, out LoadMode OutMode))
mode = OutMode;

if (load != null)
{
load.Enumerator = MethodInfo.Invoke(null, null) as IEnumerator;
Loads.Add(load);
continue;
}

if (mode != null)
Loads.Add(new LoadAttribute
{
Mode = (LoadMode)mode,
Enumerator = MethodInfo.Invoke(null, null) as IEnumerator
});
}

Info($"Statically Initialized Class {type}", "LoadAttribute");
}
}
16 changes: 16 additions & 0 deletions NextShip.Api/Attributes/NextEventListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Reflection;
using NextShip.Api.Interfaces;

namespace NextShip.Api.Attributes;

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public sealed class NextEventListener : Attribute
{
public static void RegisterFormAssembly(Assembly assembly, IEventManager manager)
{
}

public static void RegisterFormService(IServiceProvider provider, IEventManager manager)
{
}
}
Loading

0 comments on commit 428b322

Please sign in to comment.