fix music start bug

rabi_display
Copy Liu 8 years ago
parent 84328069c5
commit daef372766
No known key found for this signature in database
GPG Key ID: 63A453DBF23409AF
  1. 27
      rabiribi_splitter/Form1.Designer.cs
  2. 126
      rabiribi_splitter/Form1.cs
  3. 92
      rabiribi_splitter/MemoryHelper.cs
  4. 24
      rabiribi_splitter/StaticData.cs
  5. 1
      rabiribi_splitter/rabiribi_splitter.csproj

@ -38,6 +38,7 @@
this.cbBossEnd = new System.Windows.Forms.CheckBox();
this.musicLabel = new System.Windows.Forms.Label();
this.cbBoss = new System.Windows.Forms.CheckBox();
this.cbComputer = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.portNum)).BeginInit();
this.SuspendLayout();
//
@ -100,9 +101,9 @@
this.cbBossStart.AutoSize = true;
this.cbBossStart.Location = new System.Drawing.Point(15, 53);
this.cbBossStart.Name = "cbBossStart";
this.cbBossStart.Size = new System.Drawing.Size(198, 16);
this.cbBossStart.Size = new System.Drawing.Size(192, 16);
this.cbBossStart.TabIndex = 12;
this.cbBossStart.Text = "Split when BOSS music STARTED";
this.cbBossStart.Text = "Split when BOSS music STARTS";
this.cbBossStart.UseVisualStyleBackColor = true;
//
// cbBossEnd
@ -112,15 +113,15 @@
this.cbBossEnd.CheckState = System.Windows.Forms.CheckState.Checked;
this.cbBossEnd.Location = new System.Drawing.Point(15, 75);
this.cbBossEnd.Name = "cbBossEnd";
this.cbBossEnd.Size = new System.Drawing.Size(192, 16);
this.cbBossEnd.Size = new System.Drawing.Size(180, 16);
this.cbBossEnd.TabIndex = 13;
this.cbBossEnd.Text = "Split when BOSS music STOPED";
this.cbBossEnd.Text = "Split when BOSS music ENDS";
this.cbBossEnd.UseVisualStyleBackColor = true;
//
// musicLabel
//
this.musicLabel.AutoSize = true;
this.musicLabel.Location = new System.Drawing.Point(15, 98);
this.musicLabel.Location = new System.Drawing.Point(13, 159);
this.musicLabel.Name = "musicLabel";
this.musicLabel.Size = new System.Drawing.Size(41, 12);
this.musicLabel.TabIndex = 14;
@ -130,18 +131,31 @@
//
this.cbBoss.AutoSize = true;
this.cbBoss.Enabled = false;
this.cbBoss.Location = new System.Drawing.Point(15, 113);
this.cbBoss.Location = new System.Drawing.Point(15, 174);
this.cbBoss.Name = "cbBoss";
this.cbBoss.Size = new System.Drawing.Size(138, 16);
this.cbBoss.TabIndex = 15;
this.cbBoss.Text = "BOSS music playing!";
this.cbBoss.UseVisualStyleBackColor = true;
//
// cbComputer
//
this.cbComputer.AutoSize = true;
this.cbComputer.Checked = true;
this.cbComputer.CheckState = System.Windows.Forms.CheckState.Checked;
this.cbComputer.Location = new System.Drawing.Point(15, 97);
this.cbComputer.Name = "cbComputer";
this.cbComputer.Size = new System.Drawing.Size(192, 16);
this.cbComputer.TabIndex = 16;
this.cbComputer.Text = "Split when find the computer";
this.cbComputer.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(334, 221);
this.Controls.Add(this.cbComputer);
this.Controls.Add(this.cbBoss);
this.Controls.Add(this.musicLabel);
this.Controls.Add(this.cbBossEnd);
@ -170,6 +184,7 @@
private System.Windows.Forms.CheckBox cbBossEnd;
private System.Windows.Forms.Label musicLabel;
private System.Windows.Forms.CheckBox cbBoss;
private System.Windows.Forms.CheckBox cbComputer;
}
}

@ -9,53 +9,61 @@ using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Timers;
using System.Windows.Forms;
namespace rabiribi_splitter
{
public partial class Form1 : Form
{
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory(int hProcess,
int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
const int PROCESS_WM_READ = 0x0010;
private static TcpClient tcpclient;
private static NetworkStream networkStream;
private static System.Threading.Timer timer;
// private int MapAddress = 0xA3353C;
// private int PtrAddr = 0x00940EE0;
// private int EnitiyOffset = 0x4e4;
// private int EntitySize = 0x6F4;
// private int MaxEntityEntry = 50;
private static System.Timers.Timer timer;
private bool bossbattle = false;
private int bossmusicid;
private int lastmusicid;
private Regex titleReg = new Regex(@"ver.*?(\d+\.?\d+.*)$");
private Thread memoryThread;
private int lastmoney;
private bool rabiribiready;
private string rabiribititle;
private string rabiver;
private int veridx;
public Form1()
{
InitializeComponent();
timer = new System.Threading.Timer(readmemory, null, 0, 10);
memoryThread=new Thread(() =>
{
while (true)
{
readmemory();
Thread.Sleep(10);
}
});
memoryThread.IsBackground = true;
memoryThread.Start();
}
private void readmemory(object state)
private void readmemory()
{
string rabiver="";
var processlist = Process.GetProcessesByName("rabiribi");
if (processlist.Length > 0)
{
Process process = processlist[0];
if (process.MainWindowTitle != rabiribititle)
{
var result = titleReg.Match(process.MainWindowTitle);
if (result.Success)
{
rabiver = result.Groups[1].Value;
if (!StaticData.VerNames.Contains(rabiver))
veridx = Array.IndexOf(StaticData.VerNames, rabiver);
if (veridx < 0)
{
this.Invoke(new Action(() =>
{
@ -67,9 +75,12 @@ namespace rabiribi_splitter
return;
}
}
else
{
veridx = -1;
this.Invoke(new Action(() =>
{
rbStatus.Text = rabiver + " Running (not support)";
@ -78,65 +89,98 @@ namespace rabiribi_splitter
return;
}
this.Invoke(new Action(() => rbStatus.Text = rabiver + " Running"));
int addr = StaticData.MusicAddr[rabiver];
byte[] buffer = new byte[4] {0, 0, 0, 0};
int bytesRead = 0;
IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
ReadProcessMemory((int) processHandle, process.MainModule.BaseAddress.ToInt32() + addr, buffer,
4, ref bytesRead);
if (buffer[0] < StaticData.MusicNames.Length)
rabiribititle = process.MainWindowTitle;
}
if (veridx < 0) return;
#region CheckMoney
if (cbComputer.Checked)
{
var newmoney = MemoryHelper.GetMemoryValue<int>(process, StaticData.MoneyAddress[veridx]);
if (newmoney - lastmoney == 17500)
{
sendsplit();
}
lastmoney = newmoney;
}
#endregion
int musicid = BitConverter.ToInt32(buffer,0);
#region Music
int musicaddr = StaticData.MusicAddr[veridx];
int musicid = MemoryHelper.GetMemoryValue<int>(process, musicaddr);
if (musicid < StaticData.MusicNames.Length)
{
if (lastmusicid != musicid)
{
this.Invoke(new Action(() => this.musicLabel.Text = StaticData.MusicNames[musicid]));
var flag = StaticData.BossMusics.Contains(musicid);
if (flag)
var bossmusicflag = StaticData.BossMusics.Contains(musicid);
if (bossmusicflag)
{
if (bossmusicid > 0 && bossmusicid != musicid)
if (bossbattle)
{
//直接换boss曲
if (cbBossStart.Checked || cbBossEnd.Checked)
{
sendsplit();
}
bossbattle = true;
this.Invoke(new Action(() => cbBoss.Checked = bossbattle));
bossmusicid = musicid;
lastmusicid = musicid;
return;
}
}
if (flag != bossbattle)
if (!bossbattle)
{
if (flag)
if (bossmusicflag) //boss music start!
{
bossbattle = true;
if (cbBossStart.Checked)
{
sendsplit();
}
bossmusicid = musicid;
}
else
}
if (bossbattle)
{
if (!bossmusicflag) //boss music end!
{
bossbattle = false;
if (cbBossEnd.Checked)
{
sendsplit();
}
}
}
bossbattle = flag;
this.Invoke(new Action(() => cbBoss.Checked = bossbattle));
lastmusicid = musicid;
}
}
else
{
this.Invoke(new Action(() => this.musicLabel.Text = "N/A"));
}
#endregion Music
#region SpecialBOSS
#endregion SpecialBOSS
this.Invoke(new Action(() => cbBoss.Checked = bossbattle));
}
else
{
rabiribititle = "";
this.Invoke(new Action(() =>
{
rbStatus.Text = "Not Found";

@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace rabiribi_splitter
{
public static class MemoryHelper
{
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory(int hProcess,
int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
private const int PROCESS_WM_READ = 0x0010;
public static T GetMemoryValue<T>(Process process, int addr)
{
int datasize;
switch (Type.GetTypeCode(typeof(T)))
{
case TypeCode.Boolean:
case TypeCode.Byte:
case TypeCode.Char:
case TypeCode.SByte:
datasize = 1;
break;
case TypeCode.Int16:
case TypeCode.UInt16:
datasize = 2;
break;
case TypeCode.Int32:
case TypeCode.UInt32:
datasize = 4;
break;
case TypeCode.Int64:
case TypeCode.UInt64:
datasize = 8;
break;
default:
throw new Exception("not supported");
}
byte[] buffer = new byte[datasize];
int bytesRead = 0;
IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
ReadProcessMemory((int) processHandle, process.MainModule.BaseAddress.ToInt32() + addr, buffer,
datasize, ref bytesRead);
switch (Type.GetTypeCode(typeof(T)))
{
case TypeCode.Boolean:
return (T)Convert.ChangeType( buffer[0] == 1,typeof(T));
case TypeCode.Byte:
case TypeCode.SByte:
return (T)Convert.ChangeType(buffer[0] , typeof(T));
case TypeCode.Char:
return (T)Convert.ChangeType((char)buffer[0], typeof(T));
case TypeCode.Int16:
return (T)Convert.ChangeType(BitConverter.ToInt16(buffer,0), typeof(T));
case TypeCode.UInt16:
return (T)Convert.ChangeType(BitConverter.ToUInt16(buffer, 0), typeof(T));
case TypeCode.Int32:
return (T)Convert.ChangeType(BitConverter.ToInt32(buffer, 0), typeof(T));
case TypeCode.UInt32:
return (T)Convert.ChangeType(BitConverter.ToUInt32(buffer, 0), typeof(T));
case TypeCode.Int64:
return (T)Convert.ChangeType(BitConverter.ToInt64(buffer, 0), typeof(T));
case TypeCode.UInt64:
return (T)Convert.ChangeType(BitConverter.ToUInt64(buffer, 0), typeof(T));
default:
throw new Exception("not supported");
}
}
}
}

@ -131,14 +131,6 @@ namespace rabiribi_splitter
"…",
};
public static Dictionary<string, int> MusicAddr = new Dictionary<string, int>()
{
{"1.65", 0xA46294},
{"1.70", 0xA69D98}
};
public static string[] VerNames = new string[] {"1.65", "1.70"};
public static int[] BossMusics = new[]
{
44,
@ -155,5 +147,21 @@ namespace rabiribi_splitter
8,
54
};
public static int[] MapAddress = { 0xA3353C,0};
public static int[] EnenyPtrAddr = { 0x00940EE0,0};
public static int[] EnenyEnitiyOffset = { 0x4e4,0};
public static int[] EnenyEntitySize = {0x6F4, 0x6F4 };
public static int[] MaxEntityEntry = { 50,50 };
public static int[] MoneyAddress = { 0xD3823C, };
public static string[] VerNames = {"1.65", "1.70"};
public static int[] MusicAddr =
{
0xA46294,
0xA69D98
};
}
}

@ -53,6 +53,7 @@
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="MemoryHelper.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StaticData.cs" />

Loading…
Cancel
Save