Merge pull request #524 from Hathor86/master

External custom gametool feature
This commit is contained in:
Hathor86 2015-11-20 13:30:14 +01:00
commit 155a08c7bb
32 changed files with 4934 additions and 4858 deletions

1
.gitignore vendored
View File

@ -246,6 +246,7 @@
/References/*.xml
/output/ELFSharp.dll
/output/dll/ELFSharp.dll
/output/GameTools/*.dll
*.opensdf
*.user
*.suo

View File

@ -157,8 +157,9 @@ namespace BizHawk.Client.Common
new PathEntry { System = "Global_NULL", SystemDisplayName="Global", Type = "Macros", Path = Path.Combine(".", "Movies", "Macros"), Ordinal = 10 },
new PathEntry { System = "Global_NULL", SystemDisplayName="Global", Type = "TAStudio states", Path = Path.Combine(".", "Movies", "TAStudio states"), Ordinal = 11 },
new PathEntry { System = "Global_NULL", SystemDisplayName="Global", Type = "Multi-Disk Bundles", Path = Path.Combine(".", "Tools"), Ordinal = 12 },
new PathEntry { System = "Global_NULL", SystemDisplayName="Global", Type = "GameTools", Path = Path.Combine(".", "GameTools"), Ordinal = 13 },
new PathEntry { System = "INTV", SystemDisplayName="Intellivision", Type = "Base", Path = Path.Combine(".", "Intellivision"), Ordinal = 0 },
new PathEntry { System = "INTV", SystemDisplayName="Intellivision", Type = "Base", Path = Path.Combine(".", "Intellivision"), Ordinal = 0 },
new PathEntry { System = "INTV", SystemDisplayName="Intellivision", Type = "ROM", Path = ".", Ordinal = 1 },
new PathEntry { System = "INTV", SystemDisplayName="Intellivision", Type = "Savestates", Path= Path.Combine(".", "State"), Ordinal = 2 },
new PathEntry { System = "INTV", SystemDisplayName="Intellivision", Type = "Save RAM", Path = Path.Combine(".", "SaveRAM"), Ordinal = 3 },

View File

@ -531,9 +531,7 @@
<Compile Include="CustomControls\ViewportPanel.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CustomControls\VirtualListView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CustomControls\VirtualListView.cs" />
<Compile Include="CustomControls\Win32.cs" />
<Compile Include="DisplayManager\DisplayManager.cs" />
<Compile Include="DisplayManager\DisplaySurface.cs" />
@ -807,6 +805,7 @@
<Compile Include="tools\HexEditor\HexFind.Designer.cs">
<DependentUpon>HexFind.cs</DependentUpon>
</Compile>
<Compile Include="tools\ICustomGameTool.cs" />
<Compile Include="tools\IToolForm.cs" />
<Compile Include="tools\Lua\EnvironmentSandbox.cs" />
<Compile Include="tools\Lua\Libraries\EmuLuaLibrary.Client.cs" />

File diff suppressed because it is too large Load Diff

View File

@ -1249,6 +1249,8 @@ namespace BizHawk.Client.EmuHawk
BasicBotMenuItem.Enabled = GlobalWin.Tools.IsAvailable<BasicBot>();
string toolPath = Path.Combine(Global.Config.PathEntries["Global", "GameTools"].Path, string.Format("{0}.dll", Global.Game.Name));
customToolToolStripMenuItem.Enabled = File.Exists(toolPath);
gameSharkConverterToolStripMenuItem.Enabled = GlobalWin.Tools.IsAvailable<GameShark>();
}
@ -1317,6 +1319,11 @@ namespace BizHawk.Client.EmuHawk
OpenLuaConsole();
}
private void CustomToolMenuItem_Click(object sender, EventArgs e)
{
GlobalWin.Tools.Load<ICustomGameTool>();
}
private void batchRunnerToolStripMenuItem_Click(object sender, EventArgs e)
{
new BatchRun().ShowDialog();

View File

@ -467,7 +467,7 @@ namespace BizHawk.Client.EmuHawk
CheckMessages();
LogConsole.PositionConsole();
for (; ; )
for (;;)
{
Input.Instance.Update();
@ -714,7 +714,7 @@ namespace BizHawk.Client.EmuHawk
{
ControllerInputCoalescer conInput = Global.ControllerInputCoalescer as ControllerInputCoalescer;
for (; ; )
for (;;)
{
// loop through all available events

View File

@ -173,4 +173,5 @@
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAAwAMAAP+BAAD/AAAA/wAAAP8QAAD/8QAA
</value>
</data>
>>>>>>> refs/remotes/TASVideos/master
</root>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Client.EmuHawk
{
/// <summary>
/// Interface to implements in order to make a custom tool for a specific game
/// </summary>
public interface ICustomGameTool:IToolForm
{
}
}

View File

@ -74,7 +74,12 @@ namespace BizHawk.Client.EmuHawk
var newTool = CreateInstance(toolType);
if (newTool is Form)
if (newTool == null)
{
return null;
}
if (newTool is Form)
{
(newTool as Form).Owner = GlobalWin.MainForm;
}
@ -502,16 +507,55 @@ namespace BizHawk.Client.EmuHawk
return CreateInstance(typeof(T));
}
private IToolForm CreateInstance(Type toolType)
{
var tool = (IToolForm)Activator.CreateInstance(toolType);
private IToolForm CreateInstance(Type toolType)
{
IToolForm tool;
// Add to our list of tools
_tools.Add(tool);
return tool;
}
//Specific case for custom tools
if (toolType == typeof(ICustomGameTool))
{
string path = Path.Combine(Global.Config.PathEntries["Global", "GameTools"].Path, string.Format("{0}.dll", Global.Game.Name));
if (File.Exists(path)
&& MessageBox.Show("A custom plugin has been found for the ROM you're loading. Do you want to load it?\r\nAccept ONLY if you trust the source and if you know what you're doing. In any other case, choose no."
, "Answer to life, universe and everything else?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
// As the object is "remote"(external to the project), the CreateInstanceFrom returns a handle.We need to Unwrap in order to make the casting
tool = System.Activator.CreateInstanceFrom(path, "BizHawk.Client.EmuHawk.CustomMainForm").Unwrap() as IToolForm;
if (tool == null)
{
MessageBox.Show("It seems that the object CustomMainForm does not implement IToolForm. Please review the code.", "Boom!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return null;
}
}
catch (MissingMethodException)
{
MessageBox.Show("It seems that the object CustomMainForm does not have a public default constructor. Please review the code.", "Boom!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return null;
}
catch (TypeLoadException)
{
MessageBox.Show("It seems that the object CustomMainForm does not exists. Please review the code.", "Boom!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return null;
}
}
else
{
return null;
}
}
else
{
tool = (IToolForm)Activator.CreateInstance(toolType);
}
public void UpdateToolsBefore(bool fromLua = false)
// Add to our list of tools
_tools.Add(tool);
return tool;
}
public void UpdateToolsBefore(bool fromLua = false)
{
if (Has<LuaConsole>())
{

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Runtime.InteropServices;
@ -21,7 +21,7 @@ namespace BizHawk.Common
var envpath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process);
try
{
string envpath_new = Path.GetDirectoryName(dllPath) + ";" + envpath;
string envpath_new = Path.GetDirectoryName(path) + ";" + envpath;
Environment.SetEnvironmentVariable("PATH", envpath_new, EnvironmentVariableTarget.Process);
_hModule = LoadLibrary(path); //consider using LoadLibraryEx instead of shenanigans?
var newfname = TempFileCleaner.RenameTempFilenameForDelete(path);

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
namespace BizHawk.Common
@ -48,22 +48,19 @@ namespace BizHawk.Common
var di = new DirectoryInfo(Path.GetTempPath());
for (; ; )
{
if (!System.Diagnostics.Debugger.IsAttached) //exceptions due to can't-delete are annoying. see this for another approach: http://www.codeproject.com/Articles/14402/Testing-File-Access-Rights-in-NET
var fis = di.GetFiles("bizdelete-*");
foreach (var fi in fis)
{
var fis = di.GetFiles("bizdelete-*");
foreach (var fi in fis)
try
{
try
{
fi.Delete();
}
catch
{
}
//try not to do more than one thing per frame
System.Threading.Thread.Sleep(100);
fi.Delete();
}
catch
{
}
//try not to do more than one thing per frame
System.Threading.Thread.Sleep(100);
}
//try not to slam the filesystem too hard, we dont want this to cause any hiccups
@ -77,5 +74,3 @@ namespace BizHawk.Common
static System.Threading.Thread thread;
}
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
@ -175,3 +175,4 @@ namespace BizHawk.Emulation.Common
}
}