From 28f21e1775585846cd89ba14c12431a83d030e8d Mon Sep 17 00:00:00 2001 From: scepheo Date: Mon, 20 Oct 2014 20:31:31 +0000 Subject: [PATCH] Lua: - LoadState through Lua isn't counted for movie RerecordCount. - Added movie.setrerecordcount and movie.getrerecordcount for people who really want to count their bot loadstates. --- .../lua/EmuLuaLibrary.Movie.cs | 29 +++++++++++++++++-- BizHawk.Client.EmuHawk/MainForm.cs | 8 +++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs index 85a0698b15..5257c55777 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs @@ -70,6 +70,15 @@ namespace BizHawk.Client.Common return Global.MovieSession.ReadOnly; } + [LuaMethodAttributes( + "getrerecordcount", + "Gets the rerecord count of the current movie." + )] + public static ulong GetRerecordCount() + { + return Global.MovieSession.Movie.Rerecords; + } + [LuaMethodAttributes( "getrerecordcounting", "Returns whether or not the current movie is incrementing rerecords on loadstate" @@ -123,11 +132,11 @@ namespace BizHawk.Client.Common [LuaMethodAttributes( "rerecordcount", - "Returns the current rerecord count for the loaded movie" + "[Deprecated] Alias of getrerecordcount" )] public static string RerecordCount() { - return Global.MovieSession.Movie.Rerecords.ToString(); + return GetRerecordCount().ToString(); } [LuaMethodAttributes( @@ -139,6 +148,22 @@ namespace BizHawk.Client.Common Global.MovieSession.ReadOnly = readOnly; } + [LuaMethodAttributes( + "setrerecordcount", + "Sets the rerecord count of the current movie." + )] + public static void SetRerecordCount(double count) + { + // Lua numbers are always double, integer precision holds up + // to 53 bits, so throw an error if it's bigger than that. + const double precisionLimit = 9007199254740992d; + + if (count > precisionLimit) + throw new Exception("Rerecord count exceeds Lua integer precision."); + + Global.MovieSession.Movie.Rerecords = (ulong)count; + } + [LuaMethodAttributes( "setrerecordcounting", "Sets whether or not the current movie will increment the rerecord counter on loadstate" diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 5073d2f890..95a0c5ad3e 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -2448,6 +2448,12 @@ namespace BizHawk.Client.EmuHawk public void LoadState(string path, string userFriendlyStateName, bool fromLua = false) // Move to client.common { + // If from lua, disable counting rerecords + bool wasCountingRerecords = Global.MovieSession.Movie.IsCountingRerecords; + + if (fromLua) + Global.MovieSession.Movie.IsCountingRerecords = false; + GlobalWin.DisplayManager.NeedsToPaint = true; if (SavestateManager.LoadStateFile(path, userFriendlyStateName)) @@ -2469,6 +2475,8 @@ namespace BizHawk.Client.EmuHawk { GlobalWin.OSD.AddMessage("Loadstate error!"); } + + Global.MovieSession.Movie.IsCountingRerecords = wasCountingRerecords; } public void LoadQuickSave(string quickSlotName, bool fromLua = false)