Skip to content

Commit

Permalink
更新鲶鱼精
Browse files Browse the repository at this point in the history
  • Loading branch information
tssailzz8 committed Mar 1, 2023
1 parent d5e22d9 commit ed94261
Show file tree
Hide file tree
Showing 21 changed files with 1,338 additions and 79 deletions.
44 changes: 33 additions & 11 deletions FetchDependencies/FetchDependencies.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.IO.Compression;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;

Expand All @@ -20,11 +22,11 @@ public async Task GetFfxivPlugin() {
var pluginZipPath = Path.Combine(DependenciesDir, "FFXIV_ACT_Plugin.zip");
var pluginPath = Path.Combine(DependenciesDir, "FFXIV_ACT_Plugin.dll");

if (!await NeedsUpdate(pluginPath))
if (!await NeedsUpdate(DependenciesDir))
return;

if (!File.Exists(pluginPath))
await DownloadPlugin(pluginPath);
await DownloadPlugin(DependenciesDir);

// ZipFile.ExtractToDirectory(pluginZipPath, DependenciesDir, overwriteFiles: true);
//File.Delete(pluginPath);
Expand All @@ -36,17 +38,31 @@ public async Task GetFfxivPlugin() {
}

private static async Task<bool> NeedsUpdate(string dllPath) {
return !File.Exists(dllPath);
var httpClient = new HttpClient();
var txtPath = Path.Combine(dllPath, "版本.txt");
if (File.Exists(txtPath))
{
using var txt = new StreamReader(txtPath);
var nowVerson = new Version(txt.ReadToEnd());
var textStream = await httpClient.GetStringAsync("https://cninact.diemoe.net/CN解析/版本.txt");
var remoteVersion = new Version(textStream);
return remoteVersion > nowVerson;

}
else
{
await DownloadPlugin(dllPath);
return true;
};
}

private static async Task DownloadPlugin(string path) {
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
//var client = new HttpClient();
//client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

client.DefaultRequestHeaders.UserAgent.TryParseAdd("request");//Set the User Agent to "request"
client.GetStringAsync("https://api.github.com/repos/TundraWork/FFXIV_ACT_Plugin_CN/releases")
.ContinueWith(ExtractOpCode).Wait();
//client.DefaultRequestHeaders.UserAgent.TryParseAdd("request");//Set the User Agent to "request"
//client.GetStringAsync("https://api.github.com/repos/TundraWork/FFXIV_ACT_Plugin_CN/releases")
// .ContinueWith(ExtractOpCode).Wait();
// string url = "";
//HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://github.com/TundraWork/FFXIV_ACT_Plugin_CN/releases/latest");
//req.Method = "HEAD";
Expand All @@ -55,12 +71,18 @@ private static async Task DownloadPlugin(string path) {
//if (myResp.StatusCode == HttpStatusCode.Redirect)
// url = myResp.GetResponseHeader("Location");
//var bcd = url.Split(@"/")[7];
var pluginPath = Path.Combine(path, "FFXIV_ACT_Plugin.dll");
var txtinPath = Path.Combine(path, "版本.txt");
var httpClient = new HttpClient();
await using var downloadStream = await httpClient.GetStreamAsync(downURL);
await using var downloadStream = await httpClient.GetStreamAsync("https://cninact.diemoe.net/CN解析/FFXIV_ACT_Plugin.dll\r\n");
await using var textStream = await httpClient.GetStreamAsync("https://cninact.diemoe.net/CN解析/版本.txt");
//await using var downloadStream = await httpClient.GetStreamAsync($"https://github.com/TundraWork/FFXIV_ACT_Plugin_CN/releases/download/{bcd}/FFXIV_ACT_Plugin.dll");
await using var zipFileStream = new FileStream(path, FileMode.Create);
await using var zipFileStream = new FileStream(pluginPath, FileMode.Create);
await downloadStream.CopyToAsync(zipFileStream);
zipFileStream.Close();
await using var zipFileStream1 = new FileStream(txtinPath, FileMode.Create);
await textStream.CopyToAsync(zipFileStream1);
zipFileStream1.Close();
}
public static string downURL;
private static void ExtractOpCode(Task<string> task)
Expand Down
10 changes: 9 additions & 1 deletion IINACT.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PostNamazu", "PostNamazu",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostNamazu", "PostNamazu\PostNamazu.csproj", "{63AF9824-73D3-4BED-BEDD-6AC0AC8FD352}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PostNamazu.OverlayHoster", "PostNamazu.OverlayHoster\PostNamazu.OverlayHoster.csproj", "{2B20BFF9-03A8-4766-BC62-A6D1D4C72A55}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostNamazu.OverlayHoster", "PostNamazu.OverlayHoster\PostNamazu.OverlayHoster.csproj", "{2B20BFF9-03A8-4766-BC62-A6D1D4C72A55}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Zodiark", "Zodiark\Zodiark.csproj", "{B875EAF5-57AC-4222-BFBE-06BFFEEC93EA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -92,6 +94,12 @@ Global
{2B20BFF9-03A8-4766-BC62-A6D1D4C72A55}.NuGet|Any CPU.Build.0 = Debug|Any CPU
{2B20BFF9-03A8-4766-BC62-A6D1D4C72A55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B20BFF9-03A8-4766-BC62-A6D1D4C72A55}.Release|Any CPU.Build.0 = Release|Any CPU
{B875EAF5-57AC-4222-BFBE-06BFFEEC93EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B875EAF5-57AC-4222-BFBE-06BFFEEC93EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B875EAF5-57AC-4222-BFBE-06BFFEEC93EA}.NuGet|Any CPU.ActiveCfg = Debug|Any CPU
{B875EAF5-57AC-4222-BFBE-06BFFEEC93EA}.NuGet|Any CPU.Build.0 = Debug|Any CPU
{B875EAF5-57AC-4222-BFBE-06BFFEEC93EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B875EAF5-57AC-4222-BFBE-06BFFEEC93EA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
25 changes: 13 additions & 12 deletions IINACT/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using FFXIV_ACT_Plugin.Common;
using FFXIV_ACT_Plugin.Config;
using IINACT.Properties;
using PostNamazu;
using RainbowMage.OverlayPlugin;

namespace IINACT
Expand Down Expand Up @@ -58,20 +59,20 @@ private static void CheckForUpdate()
{
try
{
var currentVersion = new Version(Application.ProductVersion);
var remoteVersionString =
new HttpClient().GetStringAsync("https://github.com/marzent/IINACT/raw/main/version").Result;
var remoteVersion = new Version(remoteVersionString);
if (remoteVersion <= currentVersion) return;
if (MessageBox.Show("An newer version of IINACT is available. Would you like to download it?",
"Update available", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
{
Process.Start("explorer", "https://github.com/marzent/IINACT/releases/latest");
}
//var currentVersion = new Version(Application.ProductVersion);
//var remoteVersionString =
// new HttpClient().GetStringAsync("https://github.com/marzent/IINACT/raw/main/version").Result;
//var remoteVersion = new Version(remoteVersionString);
//if (remoteVersion <= currentVersion) return;
//if (MessageBox.Show("An newer version of IINACT is available. Would you like to download it?",
// "Update available", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
//{
// Process.Start("explorer", "https://github.com/marzent/IINACT/releases/latest");
//}
}
catch
{
MessageBox.Show("Failed to check for updates.");
//MessageBox.Show("Failed to check for updates.");
}
}

Expand All @@ -88,7 +89,7 @@ private void InitOverlayPlugin()

pluginMain.InitPlugin(opPanel, opLabel);
var post = new PostNamazu.PostNamazu();
post.InitPlugin(opPanel,opLabel);
post.InitPlugin(opPanel, opLabel);

}

Expand Down
100 changes: 77 additions & 23 deletions PostNamazu/Actions/Command.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using PostNamazu.Attributes;
using GreyMagic;
using PostNamazu.Common;

namespace PostNamazu.Actions
Expand All @@ -28,41 +29,94 @@ public override void GetOffsets()
ModuleOffsetPtr = SigScanner.ScanText("48 8D 8F ?? ?? ?? ?? 4C 8B C7 48 8D 54 24 ??") + 3;
ModuleOffset = SigScanner.ReadInt32(ModuleOffsetPtr);
}
[StructLayout(LayoutKind.Explicit, Size = 0x68)]
struct ChatBoxString
{
[FieldOffset(0x0)] public IntPtr StringPtr;
[FieldOffset(0x8)] public long BufSize;
[FieldOffset(0x10)] public long StringLength;
[FieldOffset(0x18)] public long Ukn;
}

/// <summary>
/// 执行给出的文本指令
/// </summary>
/// <param name="command">文本指令</param>
[Command("command")] [Command("DoTextCommand")]
/// <summary>
/// 执行给出的文本指令
/// </summary>
/// <param name="command">文本指令</param>
[Command("command")] [Command("DoTextCommand")]
public void DoTextCommand(string command)
{
if (!isReady)
throw new Exception("没有对应的游戏进程");

if (command == "")
throw new Exception("指令为空");
string[] array = command.Split(new char[]
{
' '
});
switch (array[0])
{
case "/p":
case "/say":
case "/s":
case "/yell":
case "/y":
case "/shout":
case "/sh":
case "/tell":
case "/t":
case "/party":
case "/alliance":
case "/a":
case "/freecompany":
case "/fc":
case "/l":
case "/beginner":

var assemblyLock = Memory.Executor.AssemblyLock;

case "/pvpteam":
case "/linkshell":
case "/cwlinkshellcmd":
throw new Exception("不支持对话命令");
default:
break;
}
if (array[0].Contains("linkshell")|| array[0].Contains("cwlinkshell"))
{
throw new Exception("不支持对话命令");
}
var flag = false;
try {
Monitor.Enter(assemblyLock, ref flag);
var array = Encoding.UTF8.GetBytes(command);
using AllocatedMemory allocatedMemory = Memory.CreateAllocatedMemory(400), allocatedMemory2 = Memory.CreateAllocatedMemory(array.Length + 30);
allocatedMemory2.AllocateOfChunk("cmd", array.Length);
allocatedMemory2.WriteBytes("cmd", array);
allocatedMemory.AllocateOfChunk<IntPtr>("cmdAddress");
allocatedMemory.AllocateOfChunk<long>("t1");
allocatedMemory.AllocateOfChunk<long>("tLength");
allocatedMemory.AllocateOfChunk<long>("t3");
allocatedMemory.Write("cmdAddress", allocatedMemory2.Address);
allocatedMemory.Write("t1", 0x40);
allocatedMemory.Write("tLength", array.Length + 1);
allocatedMemory.Write("t3", 0x00);
_ = Memory.CallInjected64<int>(ProcessChatBoxPtr, RaptureModule, allocatedMemory.Address, UiModule);
var cmd = command;
ChatBoxString cmdString;
var cmdBytes = Encoding.UTF8.GetBytes(cmd);
var stringMemPtr = Memory.Memory.Allocate(cmdBytes.Length + 30);
Memory.Memory.WriteBytes(stringMemPtr, cmdBytes);
cmdString.StringPtr = stringMemPtr;
cmdString.BufSize = 0x40;
cmdString.StringLength = cmdBytes.Length + 1;
cmdString.Ukn = 0;
var stringMem = Memory.Memory.Allocate(400);
Memory.Memory.Write<ChatBoxString>(stringMem, cmdString);
Memory.Execute(0, ProcessChatBoxPtr, RaptureModule, stringMem, IntPtr.Zero, 0);


//Monitor.Enter(assemblyLock, ref flag);
// var array = Encoding.UTF8.GetBytes(command);
// using AllocatedMemory allocatedMemory = Memory.CreateAllocatedMemory(400), allocatedMemory2 = Memory.CreateAllocatedMemory(array.Length + 30);
// allocatedMemory2.AllocateOfChunk("cmd", array.Length);
// allocatedMemory2.WriteBytes("cmd", array);
// allocatedMemory.AllocateOfChunk<IntPtr>("cmdAddress");
// allocatedMemory.AllocateOfChunk<long>("t1");
// allocatedMemory.AllocateOfChunk<long>("tLength");
// allocatedMemory.AllocateOfChunk<long>("t3");
// allocatedMemory.Write("cmdAddress", allocatedMemory2.Address);
// allocatedMemory.Write("t1", 0x40);
// allocatedMemory.Write("tLength", array.Length + 1);
// allocatedMemory.Write("t3", 0x00);
// _ = Memory.CallInjected64<int>(ProcessChatBoxPtr, RaptureModule, allocatedMemory.Address, UiModule);
}
finally {
if (flag) Monitor.Exit(assemblyLock);

}
}
}
Expand Down
7 changes: 2 additions & 5 deletions PostNamazu/Actions/Mark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,14 @@ private void DoMarkingByActorID(uint ActorID, MarkType markingType, bool localOn
if (ActorID != 0xE000000 && combatant == null) {
throw new Exception($"未能找到{ActorID}");
}
var assemblyLock = Memory.Executor.AssemblyLock;
var flag = false;
try {
Monitor.Enter(assemblyLock, ref flag);
if (!localOnly)
_ = Memory.CallInjected64<char>(MarkingFunc, MarkingController, markingType, ActorID);
_ = Memory.Execute(MarkingFunc, MarkingController, markingType, ActorID);
else //本地标点的markingType从0开始,因此需要-1
_ = Memory.CallInjected64<char>(LocalMarkingFunc, MarkingController, markingType - 1, ActorID, 0);
_ = Memory.Execute(LocalMarkingFunc, MarkingController, markingType - 1, ActorID, 0);
}
finally {
if (flag) Monitor.Exit(assemblyLock);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion PostNamazu/Actions/Preset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void DoInsertPreset(WayMarks waymarks)
};

byte[] importdata = ConstructGamePreset(waymarks);
Memory.WriteBytes(SlotOffset, importdata);
Memory.Memory.WriteBytes(SlotOffset, importdata);

}
/// <summary>
Expand Down
22 changes: 11 additions & 11 deletions PostNamazu/Actions/WayMark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public void SaveWaymark()

Waymark ReadWaymark(IntPtr addr, WaymarkID id) => new()
{
X = Memory.Read<float>(addr),
Y = Memory.Read<float>(addr + 0x4),
Z = Memory.Read<float>(addr + 0x8),
Active = Memory.Read<byte>(addr + 0x1C) == 1,
X = Memory.Memory.Read<float>(addr),
Y = Memory.Memory.Read<float>(addr + 0x4),
Z = Memory.Memory.Read<float>(addr + 0x8),
Active = Memory.Memory.Read<byte>(addr + 0x1C) == 1,
ID = id
};

Expand Down Expand Up @@ -138,16 +138,16 @@ private void WriteWaymark(Waymark waymark, int id = -1)
};

// Write the X, Y and Z coordinates
Memory.Write(markAddr, waymark.X);
Memory.Write(markAddr + 0x4, waymark.Y);
Memory.Write(markAddr + 0x8, waymark.Z);
Memory.Memory.Write(markAddr, waymark.X);
Memory.Memory.Write(markAddr + 0x4, waymark.Y);
Memory.Memory.Write(markAddr + 0x8, waymark.Z);

Memory.Write(markAddr + 0x10, (int)(waymark.X * 1000));
Memory.Write(markAddr + 0x14, (int)(waymark.Y * 1000));
Memory.Write(markAddr + 0x18, (int)(waymark.Z * 1000));
Memory.Memory.Write(markAddr + 0x10, (int)(waymark.X * 1000));
Memory.Memory.Write(markAddr + 0x14, (int)(waymark.Y * 1000));
Memory.Memory.Write(markAddr + 0x18, (int)(waymark.Z * 1000));

// Write the active state
Memory.Write(markAddr + 0x1C, (byte)(waymark.Active ? 1 : 0));
Memory.Memory.Write(markAddr + 0x1C, (byte)(waymark.Active ? 1 : 0));
}

}
Expand Down
6 changes: 3 additions & 3 deletions PostNamazu/Common/NamazuModule.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using GreyMagic;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Zodiark;

namespace PostNamazu.Common
{
Expand All @@ -14,7 +14,7 @@ internal abstract class NamazuModule
protected PostNamazu PostNamazu;
protected FFXIV_ACT_Plugin.FFXIV_ACT_Plugin FFXIV_ACT_Plugin => PostNamazu?.FFXIV_ACT_Plugin;
protected Process FFXIV => PostNamazu?.FFXIV;
protected ExternalProcessMemory Memory => PostNamazu?.Memory;
protected ZodiarkProcess Memory => PostNamazu?.Memory;
protected SigScanner SigScanner => PostNamazu?.SigScanner;

internal bool isReady = false;
Expand Down
Loading

0 comments on commit ed94261

Please sign in to comment.