8000 对对战记录上传工具进行了汉化,加入提取replay中名称信息的功能,修复了若干bug · hxdnshx/PYHHelper@66f6681 · GitHub
[go: up one dir, main page]

Skip to content

Commit 66f6681

Browse files
committed
对对战记录上传工具进行了汉化,加入提取replay中名称信息的功能,修复了若干bug
1 parent dd5a2d8 commit 66f6681

File tree

14 files changed

+879
-4
lines changed
  • Properties
  • 14 files changed

    +879
    -4
    lines changed

    PYHHelper.sln

    Lines changed: 24 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -18,6 +18,10 @@ Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-co
    1818
    EndProject
    1919
    Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveHelper", "LiveHelper\LiveHelper.csproj", "{DBFBAAD7-F8B6-48FD-88F1-762BA30F729A}"
    2020
    EndProject
    21+
    Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Haushaltsbuch", "Haushaltsbuch\Haushaltsbuch\Haushaltsbuch.vcxproj", "{F5FA1970-E595-47CB-AA92-6B1B885E1F1D}"
    22+
    EndProject
    23+
    Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProfileUploader", "ProfileUploader\ProfileUploader.csproj", "{A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}"
    24+
    EndProject
    2125
    Global
    2226
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
    2327
    Debug|Any CPU = Debug|Any CPU
    @@ -94,6 +98,26 @@ Global
    9498
    {DBFBAAD7-F8B6-48FD-88F1-762BA30F729A}.Release|x64.Build.0 = Release|Any CPU
    9599
    {DBFBAAD7-F8B6-48FD-88F1-762BA30F729A}.Release|x86.ActiveCfg = Release|Any CPU
    96100
    {DBFBAAD7-F8B6-48FD-88F1-762BA30F729A}.Release|x86.Build.0 = Release|Any CPU
    101+
    {F5FA1970-E595-47CB-AA92-6B1B885E1F1D}.Debug|Any CPU.ActiveCfg = Debug|Win32
    102+
    {F5FA1970-E595-47CB-AA92-6B1B885E1F1D}.Debug|x64.ActiveCfg = Debug|Win32
    103+
    {F5FA1970-E595-47CB-AA92-6B1B885E1F1D}.Debug|x86.ActiveCfg = Debug|Win32
    104+
    {F5FA1970-E595-47CB-AA92-6B1B885E1F1D}.Debug|x86.Build.0 = Debug|Win32
    105+
    {F5FA1970-E595-47CB-AA92-6B1B885E1F1D}.Release|Any CPU.ActiveCfg = Release|Win32
    106+
    {F5FA1970-E595-47CB-AA92-6B1B885E1F1D}.Release|x64.ActiveCfg = Release|Win32
    107+
    {F5FA1970-E595-47CB-AA92-6B1B885E1F1D}.Release|x86.ActiveCfg = Release|Win32
    108+
    {F5FA1970-E595-47CB-AA92-6B1B885E1F1D}.Release|x86.Build.0 = Release|Win32
    109+
    {A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    110+
    {A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
    111+
    {A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Debug|x64.ActiveCfg = Debug|Any CPU
    112+
    {A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Debug|x64.Build.0 = Debug|Any CPU
    113+
    {A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Debug|x86.ActiveCfg = Debug|Any CPU
    114+
    {A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Debug|x86.Build.0 = Debug|Any CPU
    115+
    {A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
    116+
    {A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Release|Any CPU.Build.0 = Release|Any CPU
    117+
    {A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Release|x64.ActiveCfg = Release|Any CPU
    118+
    {A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Release|x64.Build.0 = Release|Any CPU
    119+
    {A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Release|x86.ActiveCfg = Release|Any CPU
    120+
    {A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Release|x86.Build.0 = Release|Any CPU
    97121
    EndGlobalSection
    98122
    GlobalSection(SolutionProperties) = preSolution
    99123
    HideSolutionNode = FALSE

    PYHHelper/Form1.Designer.cs

    Lines changed: 13 additions & 0 deletions
    Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

    PYHHelper/Form1.cs

    Lines changed: 33 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -29,6 +29,7 @@ public partial class Form1 : Form
    2929

    3030
    public Form1()
    3131
    {
    32+
    rand = new Random();
    3233
    InitializeComponent();
    3334
    TH155Addr.TH155AddrStartup(1, this.Handle, TH155Addr.TH155CALLBACK);
    3435
    fsw = new FileSystemWatcher();
    @@ -80,6 +81,7 @@ private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    8081
    TH155Addr.TH155AddrCleanup();
    8182
    }
    8283

    84+
    private Random rand;
    8385
    private void Form1_Load(object sender, EventArgs e)
    8486
    {
    8587

    @@ -214,8 +216,26 @@ private void timer1_Tick_1(object sender, EventArgs e)
    214216
    currentindex = currentindex % listBox1.Items.Count;
    215217
    continue;
    216218
    }
    219+
    220+
    var replayData = ReplayReader.Open(listBox1.Items[currentindex].ToString());
    221+
    //P1 - 6 P2 - 7
    222+
    File.WriteAllText("P1.txt",replayData[6]);
    223+
    File.WriteAllText("P2.txt",replayData[7]);
    217224
    File.Copy(listBox1.Items[currentindex].ToString(), textBox1.Text, true);
    218-
    currentindex = (currentindex + 1) % listBox1.Items.Count;
    225+
    try
    226+
    {
    227+
    if (listBox1.Items.Count > 1000)
    228+
    {
    229+
    listBox1.Items.RemoveAt(rand.Next(1, 999));
    230+
    }
    231+
    232+
    currentindex = (currentindex + 1 + rand.Next(1, 100)) % listBox1.Items.Count;
    233+
    }
    234+
    catch (Exception ex)
    235+
    {
    236+
    throw ex;
    237+
    }
    238+
    219239
    break;
    220240
    }
    221241

    @@ -299,6 +319,8 @@ private Task ReturnToGameMenu()
    299319
    return;
    300320
    for (; ; )
    301321
    {
    322+
    if (TH155Addr.TH155AddrGetState() == 0)
    323+
    return;
    302324
    SetTH155Foreground();
    303325
    if (IsMainMenu())
    304326
    break;
    @@ -332,6 +354,8 @@ private Task SwitchTo(int loc, Func<bool> predice = null)
    332354

    333355
    for (; ; )
    334356
    {
    357+
    if (TH155Addr.TH155AddrGetState() == 0)
    358+
    return;
    335359
    var cursorstat_y = TH155Addr.TH155GetRTChildInt("menu/cursor/target_y");
    336360
    SetTH155Foreground();
    337361
    if (predice!=null && predice())
    @@ -350,7 +374,7 @@ private Task WaitingUntil(Func<bool> predice)
    350374
    {
    351375
    for (;;)
    352376
    {
    353-
    if (predice())
    377+
    if (predice() || TH155Addr.TH155AddrGetState() == 0)
    354378
    return;
    355379
    Thread.Sleep(1000);
    356380
    }
    @@ -413,6 +437,8 @@ private async void ToNetwork(string IPAddress)
    413437
    TH155Addr.VirtualPress(0x43);
    414438
    Thread.Sleep(200);
    415439
    TH155Addr.VirtualPress(90);
    440+
    File.WriteAllText("P1.txt", "");
    441+
    File.WriteAllText("P2.txt", "");
    416442
    Thread.Sleep(5000);
    417443
    await WaitingUntil(() =>
    418444
    {
    @@ -461,5 +487,10 @@ private void button3_Click(object sender, EventArgs e)
    461487
    {
    462488
    Task.Run((Action)FetchTenco);
    463489
    }
    490+
    491+
    private void button4_Click(object sender, EventArgs e)
    492+
    {
    493+
    ReplayReader.Open(listBox1.Items[3].ToString());
    494+
    }
    464495
    }
    465496
    }

    PYHHelper/PYHHelper.csproj

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -26,7 +26,7 @@
    2626
    F438 <PlatformTarget>AnyCPU</PlatformTarget>
    2727
    <DebugType>pdbonly</DebugType>
    2828
    <Optimize>true</Optimize>
    29-
    <OutputPath>bin\Release\</OutputPath>
    29+
    <OutputPath>..\Release\</OutputPath>
    3030
    <DefineConstants>TRACE</DefineConstants>
    3131
    <ErrorReport>prompt</ErrorReport>
    3232
    <WarningLevel>4</WarningLevel>
    @@ -53,6 +53,7 @@
    5353
    </Compile>
    5454
    <Compile Include="Program.cs" />
    5555
    <Compile Include="Properties\AssemblyInfo.cs" />
    56+
    <Compile Include="ReplayReader.cs" />
    5657
    <Compile Include="TH155Addr.cs" />
    5758
    <EmbeddedResource Include="Form1.resx">
    5859
    <DependentUpon>Form1.cs</DependentUpon>

    PYHHelper/ReplayReader.cs

    Lines changed: 55 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,55 @@
    1+
    using System;
    2+
    using System.Collections.Generic;
    3+
    using System.IO;
    4+
    using System.Linq;
    5+
    using System.Text;
    6+
    using System.Threading.Tasks;
    7+
    using System.IO.Compression;
    8+
    9+
    namespace PYHHelper
    10+
    {
    11+
    class ReplayReader
    12+
    {
    13+
    private static byte[] PacketBegin = new byte[] {0x10, 0x00, 0x00, 0x08};
    14+
    static byte[] Slice(byte[] arr, int offset, int length)
    15+
    {
    16+
    return arr.Skip(offset).Take(length).ToArray();
    17+
    }
    18+
    public static List<string> Open(string fileName)
    19+
    {
    20+
    byte[] rep = File.ReadAllBytes(fileName);
    21+
    Int32 metaLength = BitConverter.ToInt32(Slice(rep, 13, 4), 0);
    22+
    23+
    byte[] CompressedMetaData = Slice(rep, 21, metaLength);
    24+
    byte[] RestData = Slice(rep, 21 + metaLength, rep.Length - 21 + metaLength);
    25+
    File.WriteAllBytes("E:\\restData.txt", RestData);
    26+
    27+
    byte[] MetaData = Inflate(CompressedMetaData);
    28+
    29+
    var Names = new List<string>();
    30+
    for (int i = 0; i < MetaData.Length; i++)
    31+
    {
    32+
    if (Slice(MetaData, i, 4).SequenceEqual(PacketBegin))
    33+
    {
    34+
    int nameLength = BitConverter.ToInt32(Slice(MetaData, i + 4, 4), 0);
    35+
    byte[] packetNameArray = Slice(MetaData, i + 8, nameLength);
    36+
    string packetName = Encoding.GetEncoding("Shift_JIS").GetString(packetNameArray);
    37+
    Names.Add(packetName);
    38+
    }
    39+
    }
    40+
    41+
    return Names;
    42+
    }
    43+
    44+
    private static byte[] Inflate(byte[] data)
    45+
    {
    46+
    MemoryStream outStream = new MemoryStream();
    47+
    MemoryStream stream = new MemoryStream();
    48+
    var ds = new DeflateStream(stream, CompressionMode.Decompress);
    49+
    stream.Write(data, 2, data.Length - 6);
    50+
    stream.Seek(0, SeekOrigin.Begin);
    51+
    ds.CopyTo(outStream);
    52+
    return outStream.ToArray();
    53+
    }
    54+
    }
    55+
    }

    ProfileUploader/ConfigHelper.cs

    Lines changed: 88 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,88 @@
    1+
    using System;
    2+
    using System.Collections.Generic;
    3+
    using System.IO;
    4+
    using System.Linq;
    5+
    using System.Runtime.Serialization;
    6+
    using System.Runtime.Serialization.Json;
    7+
    using System.Text;
    8+
    using System.Xml;
    9+
    10+
    namespace ProfileUploader
    11+
    {
    12+
    public static class ConfigHelper
    13+
    {
    14+
    /// <summary>
    15+
    /// 加载,或者新建一个对应的数据结构
    16+
    /// </summary>
    17+
    /// <typeparam name="T">要从Xml中加载的数据结构</typeparam>
    18+
    /// <param name="dt"></param>
    19+
    /// <param name="Path"></param>
    20+
    /// <returns></returns>
    21+
    public static T LoadOrCreate<T>(this object dt, string Path) where T : new()
    22+
    {
    23+
    T ret;
    24+
    DataContractSerializer serializer = new DataContractSerializer(typeof(T));
    25+
    if (File.Exists(Path))
    26+
    {
    27+
    FileStream stream = new FileStream(Path, FileMode.Open, FileAccess.Read);
    28+
    ret = (T)serializer.ReadObject(stream);
    29+
    30+
    stream.Close();
    31+
    }
    32+
    else
    33+
    {
    34+
    ret = new T();
    35+
    }
    36+
    return ret;
    37+
    }
    38+
    //https://stackoverflow.com/questions/1879395/how-to-generate-a-stream-from-a-string
    39+
    public static Stream GenerateStreamFromString(string s)
    40+
    {
    41+
    MemoryStream stream = new MemoryStream();
    42+
    StreamWriter writer = new StreamWriter(stream);
    43+
    writer.Write(s);
    44+
    writer.Flush();
    45+
    stream.Position = 0;
    46+
    return stream;
    47+
    }
    48+
    /// <summary>
    49+
    /// 保存数据结构到文件(同时输出xml跟json格式)
    50+
    /// </summary>
    51+
    /// <typeparam name="T"></typeparam>
    52+
    /// <param name="dt"></param>
    53+
    /// <param name="Path"></param>
    54+
    /// <param name="list"></param>
    55+
    public static void SaveData<T>(this object dt, string Path, T list)
    56+
    {
    57+
    DataContractSerializer serializer = new DataContractSerializer(typeof(T));
    58+
    try
    59+
    {
    60+
    var settings = new XmlWriterSettings { Indent = true };
    61+
    62+
    using (var w = XmlWriter.Create(Path, settings))
    63+
    {
    64+
    serializer.WriteObject(w, list);
    65+
    }
    66+
    }
    67+
    catch (Exception ex)
    68+
    {
    69+
    Console.WriteLine(ex);
    70+
    }
    71+
    }
    72+
    73+
    public static string MixPath(this string realPath, string relativePath)
    74+
    {
    75+
    bool endWithDiv = (realPath.Last() == '/' || realPath.Last() == '\\');
    76+
    bool startWithDiv = (relativePath.First() == '/' || relativePath.First() == '\\');
    77+
    if (endWithDiv && startWithDiv)
    78+
    {
    79+
    realPath += "." + relativePath;
    80+
    }
    81+
    else if (!startWithDiv && !endWithDiv)
    82+
    realPath += "/" + relativePath;
    83+
    else
    84+
    realPath += relativePath;
    85+
    return realPath;
    86+
    }
    87+
    }
    88+
    }

    ProfileUploader/DateHelper.cs

    Lines changed: 20 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,20 @@
    1+
    using System;
    2+
    using System.Collections.Generic;
    3+
    using System.Text;
    4+
    5+
    namespace ProfileUploader
    6+
    {
    7+
    public static class DateHelper
    8+
    {
    9+
    public static DateTime FromUnixTime(this long unixTime)
    10+
    {
    11+
    return epoch.AddMilliseconds(unixTime / 1000);
    12+
    }
    13+
    private static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    14+
    15+
    public static long ToUnixTime(this DateTime date)
    16+
    {
    17+
    return Convert.ToInt64((date.ToUniversalTime() - epoch).TotalMilliseconds * 1000);
    18+
    }
    19+
    }
    20+
    }

    ProfileUploader/GZipHelper.cs

    Lines changed: 35 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,35 @@
    1+
    using System;
    2+
    using System.Collections.Generic;
    3+
    using System.IO;
    4+
    using System.IO.Compression;
    5+
    using System.Text;
    6+
    7+
    namespace ProfileUploader
    8+
    {
    9+
    public static class GZipHelper
    10+
    {
    11+
    //From : https://stackoverflow.com/questions/13879911/decompress-a-gzip-compressed-http-response-chunked-encoding
    12+
    public static byte[] Decompress_GZip(byte[] gzip)
    13+
    {
    14+
    using (GZipStream stream = new GZipStream(new MemoryStream(gzip),
    15+
    CompressionMode.Decompress))
    16+
    A30D {
    17+
    byte[] buffer = new byte[1024];
    18+
    using (MemoryStream memory = new MemoryStream())
    19+
    {
    20+
    int count = 0;
    21+
    do
    22+
    {
    23+
    count = stream.Read(buffer, 0, 1024);
    24+
    if (count > 0)
    25+
    {
    26+
    memory.Write(buffer, 0, count);
    27+
    }
    28+
    }
    29+
    while (count > 0);
    30+
    return memory.ToArray();
    31+
    }
    32+
    }
    33+
    }
    34+
    }
    35+
    }

    0 commit comments

    Comments
     (0)
    0