Skip to content

Commit

Permalink
Impl TTT Calibration via NTR connection
Browse files Browse the repository at this point in the history
Only support gameplay started via One Click for now.
close #15
  • Loading branch information
wwwwwwzx committed Aug 19, 2017
1 parent cb431f8 commit 5336f8d
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 49 deletions.
20 changes: 10 additions & 10 deletions 3DSRNGTool/Gen6/TinyTimeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public void AdvancetoNextCall(out uint rand)
switch (calltype)
{
case 0: // Blink 0x72B9D0
Addfront(Currentframe, rand < 0x55555556 ? 1 : 2);
Addfront(Currentframe, rand > 0x55555555 ? 1 : 2);
break;
case 1: // Blink 0x72B9FC
Add(Currentframe + getcooldown2(rand), 2);
break;
case 2: // Blink 0x72B9E4
case 1: // Blink 0x72B9E4
Add(Currentframe + getcooldown1(rand), 0);
break;
case 2: // Blink 0x72B9FC
Add(Currentframe + getcooldown2(rand), 1);
break;
case 3: // Stretch 0x70B108
Add(Currentframe + getcooldown3(rand), 3);
break;
Expand All @@ -79,11 +79,11 @@ public void AdvancetoNextCall(out uint rand)
}
}

private static int getcooldown1(uint rand) => (int)((((rand * 60ul) >> 32) * 2 + 124));
private static int getcooldown2(uint rand) => rand < 0x55555556 ? 20 : 12;
private static int getcooldown3(uint rand) => (int)((((rand * 90ul) >> 32) * 2 + 720));
private static int getcooldown4(uint rand) => rand % 3 == 0 ? 360 : 180;
private static int getcooldown5(uint rand) => (int)((((rand * 10ul) >> 32) * 30 + 60));
public static int getcooldown1(uint rand) => (int)((((rand * 60ul) >> 32) * 2 + 124));
public static int getcooldown2(uint rand) => rand < 0x55555556 ? 20 : 12;
public static int getcooldown3(uint rand) => (int)((((rand * 90ul) >> 32) * 2 + 720));
public static int getcooldown4(uint rand) => rand % 3 == 0 ? 360 : 180;
public static int getcooldown5(uint rand) => (int)((((rand * 10ul) >> 32) * 30 + 60));
}

public class TinyTimeline
Expand Down
52 changes: 48 additions & 4 deletions 3DSRNGTool/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class MainForm : Form
private bool Gen6 => Ver < 5;
private bool IsTransporter => Ver == 4;
private bool Gen7 => 5 <= Ver && Ver < 9;
private bool gen6timeline => Gen6 && CreateTimeline.Checked && TTT != null && TTT.Gen6Tiny.Any(t => t > 0);
private bool gen6timeline => Gen6 && CreateTimeline.Checked && TTT.Gen6Tiny.Any(t => t > 0);
private bool gen6timeline_available => Gen6 && (Method == 0 && !AlwaysSynced.Checked || Method == 2);
private byte lastgen;
private EncounterArea ea;
Expand Down Expand Up @@ -118,6 +118,8 @@ private void MainForm_Load(object sender, EventArgs e)
private void MainForm_Close(object sender, FormClosedEventArgs e)
{
Properties.Settings.Default.Save();
if (TTT.B_Stop.Visible)
TTT.Calibrate(-1, 0, 0);
ntrhelper?.B_Disconnect_Click(null, null);
}

Expand Down Expand Up @@ -1317,7 +1319,7 @@ private void DGV_CellFormatting(object sender, DataGridViewCellFormattingEventAr

// Tools
private IVRange IVInputer = new IVRange();
private TinyTimelineTool TTT;
private TinyTimelineTool TTT = new TinyTimelineTool();
private Gen7MainRNGTool gen7tool;
private NTRHelper ntrhelper;

Expand All @@ -1327,9 +1329,9 @@ private void DGV_CellFormatting(object sender, DataGridViewCellFormattingEventAr
//Gen6
private void OpenTinyTool(object sender, EventArgs e)
{
if (TTT == null) TTT = new TinyTimelineTool();
TranslateInterface(TTT, curlanguage);
TTT.Show();
TTT.Focus();
}
private void M_NTRHelper_Click(object sender, EventArgs e)
{
Expand All @@ -1339,7 +1341,7 @@ private void M_NTRHelper_Click(object sender, EventArgs e)
}
public void OnConnected_Changed(bool IsConnected)
{
B_GetTiny.Enabled = IsConnected;
TTT.B_Cali.Enabled = B_GetTiny.Enabled = IsConnected;
}
public void parseNTRInfo(string name, object data)
{
Expand Down Expand Up @@ -1367,6 +1369,48 @@ public void parseNTRInfo(string name, object data)
case "TTT":
TTT.Gen6Tiny = (uint[])data;
return;
case "BreakPoint":
int CurrentFrame = NTRHelper.ntrclient.getCurrentFrame();
if (CurrentFrame == NtrClient.FrameMax)
{
TTT.Calibrate(-1, 0, 0);
Error("Fail to calibrate! Please check your initial seed!");
return;
}
if (TTT.B_Cali.Visible)
return;
switch ((uint)data)
{
// Blink
case 0x72B9D0:
case 0x6F1324: // rand(3)
TTT.Calibrate(0, CurrentFrame, CurrentFrame);
break;
case 0x72B9E4:
case 0x6F1338: // rand(60)
var delay1 = TinyStatus.getcooldown1(NTRHelper.ntrclient.ReadTinyRNG().Nextuint());
TTT.Calibrate(1, CurrentFrame, CurrentFrame + delay1);
break;
case 0x72B9FC:
case 0x6F1350: // rand(3)
var delay2 = TinyStatus.getcooldown2(NTRHelper.ntrclient.ReadTinyRNG().Nextuint());
TTT.Calibrate(2, CurrentFrame, CurrentFrame + delay2);
break;

// Stretch
case 0x70B108:
case 0x736F64:
var delay3 = TinyStatus.getcooldown3(NTRHelper.ntrclient.ReadTinyRNG().Nextuint());
TTT.Calibrate(3, CurrentFrame, CurrentFrame + delay3);
break;

default:
TTT.Calibrate(-1, 0, 0);
Error("Unknown Timeline Type");
return;
}
NTRHelper.ntrclient.resume();
return;
}
}
private void M_Gen6SeedFinder_Click(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion 3DSRNGTool/MainForm_Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void Search6_Normal()

private void Search6_Timeline()
{
if (TTT == null || TTT.Gen6Tiny.All(t => t == 0))
if (TTT.Gen6Tiny.All(t => t == 0))
{
Error("Please Calibrate Timeline");
return;
Expand Down
57 changes: 41 additions & 16 deletions 3DSRNGTool/Subforms/TinyTimelineTool.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5336f8d

Please sign in to comment.