From bf444802a457302fb27841dff71b37be735ea0c6 Mon Sep 17 00:00:00 2001 From: wcko87 Date: Sat, 15 Apr 2017 02:01:23 +0800 Subject: [PATCH] Add feature: automatically start timer when starting game. Experimental. 1.75 only for same reason as before. Meh. lazyness --- rabi_splitter_WPF/MainContext.cs | 15 +++++- rabi_splitter_WPF/MainWindow.xaml | 1 + rabi_splitter_WPF/MainWindow.xaml.cs | 74 ++++++++++++++++++---------- rabi_splitter_WPF/StaticData.cs | 3 +- 4 files changed, 64 insertions(+), 29 deletions(-) diff --git a/rabi_splitter_WPF/MainContext.cs b/rabi_splitter_WPF/MainContext.cs index 64329f8..c19c3b6 100644 --- a/rabi_splitter_WPF/MainContext.cs +++ b/rabi_splitter_WPF/MainContext.cs @@ -147,6 +147,7 @@ namespace rabi_splitter_WPF private string _gameMusic; private bool _igt; public bool _autoReset; + public bool _autoStart; public bool Noah1Reload { get { return _noah1Reload; } @@ -312,6 +313,17 @@ namespace rabi_splitter_WPF } } + public bool AutoStart + { + get { return _autoStart; } + set + { + if (value == _autoStart) return; + _autoStart = value; + OnPropertyChanged(nameof(AutoStart)); + } + } + public bool AutoReset { get { return _autoReset; } @@ -324,7 +336,7 @@ namespace rabi_splitter_WPF } } - + public bool readyToStartGame = false; public string oldtitle; public int veridx; public int lastmoney; @@ -353,6 +365,7 @@ namespace rabi_splitter_WPF this.ServerPort = 16834; this.Igt = true; this.Noah1Reload = false; + this.AutoStart = false; this.AutoReset = true; diff --git a/rabi_splitter_WPF/MainWindow.xaml b/rabi_splitter_WPF/MainWindow.xaml index ec37d13..449ebbd 100644 --- a/rabi_splitter_WPF/MainWindow.xaml +++ b/rabi_splitter_WPF/MainWindow.xaml @@ -38,6 +38,7 @@ + diff --git a/rabi_splitter_WPF/MainWindow.xaml.cs b/rabi_splitter_WPF/MainWindow.xaml.cs index 4586315..ab0ce7b 100644 --- a/rabi_splitter_WPF/MainWindow.xaml.cs +++ b/rabi_splitter_WPF/MainWindow.xaml.cs @@ -94,7 +94,40 @@ namespace rabi_splitter_WPF } #endregion - + + #region Detect Start Game + + { + int blackness = MemoryHelper.GetMemoryValue(process, StaticData.BlacknessAddr[mainContext.veridx]); // blackness + if (blackness == 0) + { + if (!mainContext.readyToStartGame) + { + mainContext.readyToStartGame = true; + } + } + else if (blackness >= 100000) + { + if (mainContext.readyToStartGame) + { + // suddent jump to 100000. + mainContext.readyToStartGame = false; + if (mainContext.AutoStart) sendstarttimer(); + DebugLog("Start Game!"); + } + } + else // 0 < blackness < 100000 + { + if (mainContext.readyToStartGame) + { + // disarm ready trigger. + mainContext.readyToStartGame = false; + } + } + } + + #endregion + #region CheckMoney if (mainContext.Computer) @@ -396,44 +429,31 @@ namespace rabi_splitter_WPF private void sendsplit() { - if (tcpclient != null && tcpclient.Connected) - { - try - { - var b = Encoding.UTF8.GetBytes("split\r\n"); - networkStream.Write(b, 0, b.Length); - } - catch (Exception) - { - - disconnect(); - } - } + SendMessage("split\r\n"); } private void sendreset() { - if (tcpclient != null && tcpclient.Connected) - { - try - { - var b = Encoding.UTF8.GetBytes("reset\r\n"); - networkStream.Write(b, 0, b.Length); - } - catch (Exception) - { + SendMessage("reset\r\n"); + } - disconnect(); - } - } + private void sendstarttimer() + { + SendMessage("starttimer\r\n"); } + private void sendigt(float time) + { + SendMessage($"setgametime {time}\r\n"); + } + + private void SendMessage(string message) { if (tcpclient != null && tcpclient.Connected) { try { - var b = Encoding.UTF8.GetBytes($"setgametime {time}\r\n"); + var b = Encoding.UTF8.GetBytes(message); networkStream.Write(b, 0, b.Length); } catch (Exception) diff --git a/rabi_splitter_WPF/StaticData.cs b/rabi_splitter_WPF/StaticData.cs index d391681..2437b3d 100644 --- a/rabi_splitter_WPF/StaticData.cs +++ b/rabi_splitter_WPF/StaticData.cs @@ -164,7 +164,8 @@ namespace rabi_splitter_WPF public static int[] TownMemberAddr = {0xD38934, 0xD5C0F4, 0xD63BC4, 0xD65BC4 }; public static int[] IGTAddr = { 0xD388E0, 0xD5C0A0, 0xD63B70, 0xD65B70 }; - + + public static int[] BlacknessAddr = { 0, 0, 0, 0xA723B0 }; public static int[] PlaytimeAddr = { 0, 0, 0, 0xD642D8 }; } }