mirror of
https://github.com/hykilpikonna/AquaDX.git
synced 2026-08-07 11:35:24 -05:00
[O] Prevent virus detect
This commit is contained in:
parent
da692d21f4
commit
d7a835c515
|
|
@ -33,7 +33,7 @@ public class PostBuildPatch : Task
|
|||
{
|
||||
foreach (var resource in assembly.MainModule.Resources.ToList())
|
||||
{
|
||||
if (resource.Name.EndsWith(".dll") && resource is EmbeddedResource embeddedResource)
|
||||
if ((resource.Name.EndsWith(".dll") || resource.Name.EndsWith(".exe")) && resource is EmbeddedResource embeddedResource)
|
||||
{
|
||||
using var compressedStream = new MemoryStream();
|
||||
using (var deflateStream = new DeflateStream(compressedStream, CompressionLevel.Optimal))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
|
|
|
|||
|
|
@ -40,15 +40,6 @@ public partial class CrashForm : Form
|
|||
|
||||
private async void CrashForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
labelVersion.Text = "AquaMai v" + FileVersionInfo.GetVersionInfo(Application.ExecutablePath).ProductVersion;
|
||||
}
|
||||
catch
|
||||
{
|
||||
labelVersion.Text = "AquaMai (Version Unknown)";
|
||||
}
|
||||
|
||||
labelStatus.Text = "正在生成错误报告... Gathering error log...";
|
||||
var exePath = Path.GetDirectoryName(Application.ExecutablePath);
|
||||
var gameDir = Path.GetDirectoryName(exePath);
|
||||
|
|
@ -69,6 +60,15 @@ public partial class CrashForm : Form
|
|||
Directory.CreateDirectory(errorLogPath);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
labelVersion.Text = "AquaMai v" + FileVersionInfo.GetVersionInfo(Path.Combine(gameDir, "Mods", "AquaMai.dll")).ProductVersion;
|
||||
}
|
||||
catch
|
||||
{
|
||||
labelVersion.Text = "AquaMai (Version Unknown)";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var logFiles = Directory.GetFiles(errorLogPath, "*.log");
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace AquaMai.ErrorReport;
|
||||
|
||||
public class Main
|
||||
public class Program
|
||||
{
|
||||
[DllImport("SHCore.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
|
|
@ -18,18 +17,12 @@ public class Main
|
|||
PER_MONITOR_AWARE = 2
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
|
||||
SetProcessDpiAwareness(DPI_AWARENESS.SYSTEM_AWARE);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new CrashForm());
|
||||
}
|
||||
|
||||
// 这是魔法
|
||||
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
|
||||
{
|
||||
return Assembly.GetExecutingAssembly();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using AquaMai.Config.Attributes;
|
||||
|
|
@ -35,6 +36,7 @@ public class ShowErrorLog
|
|||
_errorUi = new GameObject("ErrorUI").AddComponent<Ui>();
|
||||
_errorUi.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
string logFile = $"{MAI2System.Path.ErrorLogPath}{DateTime.Now:yyyyMMddHHmmss}.log";
|
||||
MelonLogger.Msg("Error Log:");
|
||||
if (File.Exists(logFile))
|
||||
|
|
@ -66,21 +68,39 @@ public class ShowErrorLog
|
|||
|
||||
public static void ApplicationOnQuittingNew()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), DateTime.Now.Ticks.ToString());
|
||||
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
using var s = GetErrorReporterStream();
|
||||
s.CopyTo(fs);
|
||||
}
|
||||
|
||||
MelonLogger.Msg("Starting Crash Handler...");
|
||||
var psi = new ProcessStartInfo
|
||||
{
|
||||
FileName = BuildInfo.ModAssembly.Location,
|
||||
Arguments = "ErrorReport",
|
||||
FileName = path,
|
||||
WorkingDirectory = Path.GetDirectoryName(Application.dataPath),
|
||||
UseShellExecute = false,
|
||||
};
|
||||
System.Diagnostics.Process.Start(psi);
|
||||
}
|
||||
|
||||
private static Stream GetErrorReporterStream()
|
||||
{
|
||||
var s = BuildInfo.ModAssembly.Assembly.GetManifestResourceStream("AquaMai.ErrorReport.exe");
|
||||
if (s != null)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
s = BuildInfo.ModAssembly.Assembly.GetManifestResourceStream("AquaMai.ErrorReport.exe.compressed");
|
||||
return new DeflateStream(s, CompressionMode.Decompress);
|
||||
}
|
||||
|
||||
private class Ui : MonoBehaviour
|
||||
{
|
||||
private string _errorLog = "";
|
||||
|
||||
|
||||
public void SetErrorLog(string text)
|
||||
{
|
||||
_errorLog = "Error Log:\n" + text;
|
||||
|
|
@ -92,14 +112,14 @@ public class ShowErrorLog
|
|||
{
|
||||
fontSize = GuiSizes.FontSize,
|
||||
alignment = TextAnchor.MiddleLeft,
|
||||
normal = new GUIStyleState(){textColor = Color.black}
|
||||
normal = new GUIStyleState() { textColor = Color.black }
|
||||
};
|
||||
|
||||
var boxStyle = new GUIStyle(GUI.skin.box)
|
||||
{
|
||||
normal = new GUIStyleState() { background = Texture2D.whiteTexture }
|
||||
};
|
||||
|
||||
|
||||
int logLineCount = Regex.Matches(_errorLog, "\n").Count + 1;
|
||||
float offset = GuiSizes.PlayerCenter * 0.12f;
|
||||
var x = GuiSizes.PlayerCenter / 2f + offset / 2f;
|
||||
|
|
@ -115,7 +135,7 @@ public class ShowErrorLog
|
|||
GUI.Label(new Rect(x + GuiSizes.PlayerWidth, y, width, height), _errorLog, labelStyle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator Show()
|
||||
{
|
||||
while (true)
|
||||
|
|
@ -124,4 +144,4 @@ public class ShowErrorLog
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{788BC472-59F7-46F6-B760-65C18BA74389}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>AquaMai</RootNamespace>
|
||||
<AssemblyName>AquaMai</AssemblyName>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
|
|
@ -48,12 +48,12 @@
|
|||
|
||||
<UsingTask TaskName="PostBuildPatch" AssemblyFile="$(OutputPath)AquaMai.Build.dll" />
|
||||
<Target Name="PostBuildPatch" AfterTargets="AfterBuild" Condition=" '$(Configuration)' == 'Release' ">
|
||||
<PostBuildPatch DllPath="$(OutputPath)$(AssemblyName).exe" />
|
||||
<PostBuildPatch DllPath="$(OutputPath)$(AssemblyName).dll" />
|
||||
</Target>
|
||||
|
||||
<UsingTask TaskName="GenerateExampleConfig" AssemblyFile="$(OutputPath)AquaMai.Build.dll" />
|
||||
<Target Name="GenerateExampleConfig" AfterTargets="AfterBuild">
|
||||
<GenerateExampleConfig DllPath="$(OutputPath)$(AssemblyName).exe" OutputPath="$(OutputPath)" />
|
||||
<GenerateExampleConfig DllPath="$(OutputPath)$(AssemblyName).dll" OutputPath="$(OutputPath)" />
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -69,8 +69,8 @@
|
|||
<EmbeddedResource Include="$(OutputPath)AquaMai.Mods.dll">
|
||||
<LogicalName>AquaMai.Mods.dll</LogicalName>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="$(OutputPath)AquaMai.ErrorReport.dll">
|
||||
<LogicalName>AquaMai.ErrorReport.dll</LogicalName>
|
||||
<EmbeddedResource Include="$(OutputPath)AquaMai.ErrorReport.exe">
|
||||
<LogicalName>AquaMai.ErrorReport.exe</LogicalName>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace AquaMai;
|
||||
|
||||
public class Program
|
||||
{
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[0])
|
||||
{
|
||||
case "ErrorReport":
|
||||
Console.WriteLine("Starting ErrorReport...");
|
||||
var erAssembly = AssemblyLoader.LoadAssemblyFromResource("AquaMai.ErrorReport.dll");
|
||||
erAssembly.GetType("AquaMai.ErrorReport.Main")
|
||||
.GetMethod("Start", BindingFlags.Public | BindingFlags.Static)
|
||||
.Invoke(null, []);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.GetType());
|
||||
Console.WriteLine(e.Message);
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -47,16 +47,11 @@ Task("Build")
|
|||
.IsDependentOn("Restore")
|
||||
.Does(() =>
|
||||
{
|
||||
if (FileExists("Output/AquaMai.dll"))
|
||||
{
|
||||
DeleteFile("Output/AquaMai.dll");
|
||||
}
|
||||
// 使用 dotnet build 进行构建
|
||||
DotNetBuild("./AquaMai.sln", new DotNetBuildSettings
|
||||
{
|
||||
Configuration = configuration
|
||||
});
|
||||
MoveFile("Output/AquaMai.exe", "Output/AquaMai.dll");
|
||||
});
|
||||
|
||||
RunTarget(target);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user