Migrate HelloWorld to new csproj format and cleanup

This commit is contained in:
YoshiRulz 2020-01-29 16:06:50 +10:00
parent 2c74b1a693
commit 7950605676
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
9 changed files with 161 additions and 369 deletions

View File

@ -1,3 +1,3 @@
#!/bin/sh
name="$(basename "$PWD").dll"
CscToolExe="$(which csc)" dotnet build -c Debug -m && cp -f "bin/Debug/$name" "../../output/ExternalTools/$name"
CscToolExe="$(which csc)" dotnet build -c Debug -m && cp -f "bin/Debug/net48/$name" "../../output/ExternalTools/$name"

View File

@ -1,3 +1,3 @@
#!/bin/sh
name="$(basename "$PWD").dll"
CscToolExe="$(which csc)" dotnet build -c Release -m && cp -f "bin/Release/$name" "../../output/ExternalTools/$name"
CscToolExe="$(which csc)" dotnet build -c Release -m && cp -f "bin/Release/net48/$name" "../../output/ExternalTools/$name"

View File

@ -0,0 +1,29 @@
<Project>
<PropertyGroup>
<CodeAnalysisRuleSet>$(ProjectDir)../../Common.ruleset</CodeAnalysisRuleSet>
<ErrorReport>prompt</ErrorReport>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<OutputPath>$(ProjectDir)bin/$(Configuration)</OutputPath>
<PlatformTarget>AnyCPU</PlatformTarget>
<RunAnalyzersDuringBuild Condition=" '$(MachineRunAnalyzersDuringBuild)' == '' ">false</RunAnalyzersDuringBuild>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>pdbonly</DebugType>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="$(ProjectDir)../../.stylecop.json" />
<Compile Remove="*.sh" />
</ItemGroup>
</Project>

View File

@ -5,65 +5,115 @@ using System.IO;
using BizHawk.Client.ApiHawk;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Client.ApiHawk.Classes.Events;
using DisplayType = BizHawk.Client.Common.DisplayType;
namespace BizHawk.Client.EmuHawk
{
/// <summary>
/// Here your first form
/// /!\ it MUST be called CustomMainForm and implements IExternalToolForm
/// Take also care of the namespace
/// </summary>
/// <remarks><see cref="IExternalToolForm">ExternalToolForms</see> must be a class named <c>CustomMainForm</c> in namespace <c>BizHawk.Client.EmuHawk</c>.</remarks>
public partial class CustomMainForm : Form, IExternalToolForm
{
#region Fields
/*
The following stuff will be automatically filled
by BizHawk runtime
*/
/// <remarks><see cref="RequiredServiceAttribute">RequiredServices</see> are populated by EmuHawk at runtime.</remarks>
[RequiredService]
internal IMemoryDomains _memoryDomains { get; set; }
private IEmulator? _emu { get; set; }
[RequiredService]
private IEmulator _emu { get; set; }
private IMemoryDomains? _memoryDomains { get; set; }
/*private members for our needed*/
private WatchList _watches;
private WatchList? _watches;
#endregion
#region cTor(s)
private WatchList Watches
{
get
{
WatchList CreateWatches()
{
var w = new WatchList(_memoryDomains, _emu?.SystemId ?? string.Empty);
w.AddRange(new[] {
Watch.GenerateWatch(_memoryDomains?.MainMemory, 0x40, WatchSize.Byte, DisplayType.Hex, true),
Watch.GenerateWatch(_memoryDomains?.MainMemory, 0x50, WatchSize.Word, DisplayType.Unsigned, true),
Watch.GenerateWatch(_memoryDomains?.MainMemory, 0x60, WatchSize.DWord, DisplayType.Hex, true)
});
return w;
}
_watches ??= CreateWatches();
return _watches;
}
}
public CustomMainForm()
{
InitializeComponent();
label_GameHash.Click += Label_GameHash_Click;
label_GameHash.Click += label_GameHash_Click;
ClientApi.BeforeQuickSave += ClientApi_BeforeQuickSave;
ClientApi.BeforeQuickLoad += ClientApi_BeforeQuickLoad;
ClientApi.BeforeQuickSave += (sender, e) =>
{
if (e.Slot != 0) return; // only take effect on slot 0
var basePath = Path.Combine(PathManager.GetSaveStatePath(Global.Game), "Test");
if (!Directory.Exists(basePath)) Directory.CreateDirectory(basePath);
ClientApi.SaveState(Path.Combine(basePath, e.Name));
e.Handled = true;
};
ClientApi.BeforeQuickLoad += (sender, e) =>
{
if (e.Slot != 0) return; // only take effect on slot 0
var basePath = Path.Combine(PathManager.GetSaveStatePath(Global.Game), "Test");
ClientApi.LoadState(Path.Combine(basePath, e.Name));
e.Handled = true;
};
}
#endregion
/// <remarks>We want <see cref="UpdateValues"/> to be called before rendering.</remarks>
public bool UpdateBefore => true;
#region Methods
public bool AskSaveChanges() => true;
private void button1_Click(object sender, EventArgs e)
/// <remarks>This is called instead of the usual <see cref="UpdateValues"/> when EmuHawk is turboing.</remarks>
public void FastUpdate() {}
public void NewUpdate(ToolFormUpdateType type) {}
/// <remarks>This is called once when the form is opened, and every time a new movie session starts.</remarks>
public void Restart()
{
ClientApi.DoFrameAdvance();
#if false
ClientApi.SetExtraPadding(50, 50);
#endif
if (Global.Game.Name != "Null")
{
Watches.RefreshDomains(_memoryDomains);
label_Game.Text = $"You're playing {Global.Game.Name}";
label_GameHash.Text = $"Hash: {Global.Game.Hash}";
}
else
{
label_Game.Text = "You're playing... nothing";
label_GameHash.Text = string.Empty;
}
}
private void button2_Click(object sender, EventArgs e)
/// <remarks>Called just before every video frame.</remarks>
public void UpdateValues()
{
ClientApi.GetInput(1);
if (Global.Game.Name == "Null" || Watches.Count < 3) return;
Watches.UpdateValues();
label_Watch1.Text = $"First watch ({Watches[0].AddressString}) current value: {Watches[0].ValueString}";
label_Watch2.Text = $"Second watch ({Watches[1].AddressString}) current value: {Watches[1].ValueString}";
label_Watch3.Text = $"Third watch ({Watches[2].AddressString}) current value: {Watches[2].ValueString}";
}
private void button1_Click(object sender, EventArgs e) => ClientApi.DoFrameAdvance();
private void button2_Click(object sender, EventArgs e) => ClientApi.GetInput(1);
private void button3_Click(object sender, EventArgs e)
{
for (int i = 0; i < 600; i++)
for (var i = 0; i < 600; i++)
{
if (i % 60 == 0)
{
Joypad j1 = ClientApi.GetInput(1);
var j1 = ClientApi.GetInput(1);
j1.AddInput(JoypadButton.A);
ClientApi.SetInput(1, j1);
@ -75,154 +125,29 @@ namespace BizHawk.Client.EmuHawk
}
ClientApi.DoFrameAdvance();
}
Joypad j = ClientApi.GetInput(1);
var j = ClientApi.GetInput(1);
j.ClearInputs();
ClientApi.SetInput(1, j);
}
private void Label_GameHash_Click(object sender, EventArgs e)
{
Clipboard.SetText(Global.Game.Hash);
}
private void label_GameHash_Click(object sender, EventArgs e) => Clipboard.SetText(Global.Game.Hash);
private void loadstate_Click(object sender, EventArgs e)
{
if (savestateName.Text.Trim() != string.Empty)
if (string.IsNullOrWhiteSpace(savestateName.Text)) return;
ClientApi.LoadState(savestateName.Text);
#if false
static void Test(BinaryReader r)
{
ClientApi.LoadState(savestateName.Text);
//BinaryStateLoader.LoadAndDetect(savestateName.Text + ".State").GetLump(BinaryStateLump.Framebuffer, false, Test);
var b = new System.Drawing.Bitmap(r.BaseStream);
}
BinaryStateLoader.LoadAndDetect($"{savestateName.Text}.State").GetLump(BinaryStateLump.Framebuffer, false, Test);
#endif
}
/*private void Test(BinaryReader r)
{
System.Drawing.Bitmap b = new System.Drawing.Bitmap(r.BaseStream);
}*/
private void saveState_Click(object sender, EventArgs e)
{
if (savestateName.Text.Trim() != string.Empty)
{
ClientApi.SaveState(savestateName.Text);
}
if (!string.IsNullOrWhiteSpace(savestateName.Text)) ClientApi.SaveState(savestateName.Text);
}
//We will override F10 quicksave behavior
private void ClientApi_BeforeQuickSave(object sender, BeforeQuickSaveEventArgs e)
{
if(e.Slot == 0)
{
string basePath = Path.Combine(PathManager.GetSaveStatePath(Global.Game), "Test");
if (!Directory.Exists(basePath))
{
Directory.CreateDirectory(basePath);
}
ClientApi.SaveState(Path.Combine(basePath, e.Name));
e.Handled = true;
}
}
//We will override F10 quickload behavior
private void ClientApi_BeforeQuickLoad(object sender, BeforeQuickLoadEventArgs e)
{
if (e.Slot == 0)
{
string basePath = Path.Combine(PathManager.GetSaveStatePath(Global.Game), "Test");
ClientApi.LoadState(Path.Combine(basePath, e.Name));
e.Handled = true;
}
}
#endregion
#region BizHawk Required methods
/// <summary>
/// Return true if you want the <see cref="UpdateValues"/> method
/// to be called before rendering
/// </summary>
public bool UpdateBefore
{
get
{
return true;
}
}
public bool AskSaveChanges()
{
return true;
}
/// <summary>
/// This method is called instead of regular <see cref="UpdateValues"/>
/// when emulator is runnig in turbo mode
/// </summary>
public void FastUpdate()
{ }
public void NewUpdate(ToolFormUpdateType type) {}
/// <summary>
/// Restart is called the first time you call the form
/// but also when you start playing a movie
/// </summary>
public void Restart()
{
//set a client padding
// ClientApi.SetExtraPadding(50, 50);
if (Global.Game.Name != "Null")
{
//first initialization of WatchList
if (_watches == null)
{
_watches = new WatchList(_memoryDomains, _emu.SystemId ?? string.Empty);
//Create some watch
Watch myFirstWatch = Watch.GenerateWatch(_memoryDomains.MainMemory, 0x40, WatchSize.Byte, BizHawk.Client.Common.DisplayType.Hex, true);
Watch mySecondWatch = Watch.GenerateWatch(_memoryDomains.MainMemory, 0x50, WatchSize.Word, BizHawk.Client.Common.DisplayType.Unsigned, true);
Watch myThirdWatch = Watch.GenerateWatch(_memoryDomains.MainMemory, 0x60, WatchSize.DWord, BizHawk.Client.Common.DisplayType.Hex, true);
//add them into the list
_watches.Add(myFirstWatch);
_watches.Add(mySecondWatch);
_watches.Add(myThirdWatch);
label_Game.Text = string.Format("You're playing {0}", Global.Game.Name);
label_GameHash.Text = string.Format("Hash: {0}", Global.Game.Hash);
}
//refresh it
else
{
_watches.RefreshDomains(_memoryDomains);
label_Game.Text = string.Format("You're playing {0}", Global.Game.Name);
label_GameHash.Text = string.Format("Hash: {0}", Global.Game.Hash);
}
}
else
{
label_Game.Text = string.Format("You aren't playing to anything");
label_GameHash.Text = string.Empty;
}
}
/// <summary>
/// This method is called when a frame is rendered
/// You can comapre it the lua equivalent emu.frameadvance()
/// </summary>
public void UpdateValues()
{
if (Global.Game.Name != "Null")
{
//we update our watches
_watches.UpdateValues();
label_Watch1.Text = string.Format("First watch ({0}) current value: {1}", _watches[0].AddressString, _watches[0].ValueString);
label_Watch2.Text = string.Format("Second watch ({0}) current value: {1}", _watches[1].AddressString, _watches[1].ValueString);
label_Watch3.Text = string.Format("Third watch ({0}) current value: {1}", _watches[2].AddressString, _watches[2].ValueString);
}
}
#endregion BizHawk Required methods
}
}

View File

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,80 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="../../DotNetBuild.Common.targets" Condition=" '$(OS)' != 'Windows_NT' " />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{288D598F-1019-4EA2-802D-14D3CC73EE90}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HelloWorld</RootNamespace>
<AssemblyName>HelloWorld</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference
HintPath="../../output/BizHawk.Client.ApiHawk.dll"
Include="BizHawk.Client.ApiHawk" />
<Reference
HintPath="../../output/BizHawk.Client.Common.dll"
Include="BizHawk.Client.Common" />
<Reference
HintPath="../../output/BizHawk.Emulation.Common.dll"
Include="BizHawk.Emulation.Common" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CustomMainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="CustomMainForm.Designer.cs">
<DependentUpon>CustomMainForm.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="CustomMainForm.resx">
<DependentUpon>CustomMainForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="icon_Hello.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(ProjectDir)../Common.props" />
<Import Project="$(ProjectDir)../NET48ExternalToolForm.props" />
<ItemGroup>
<EmbeddedResource Include="icon_Hello.ico" />
</ItemGroup>
<ItemGroup>
<Compile Update="CustomMainForm.cs" SubType="Form" />
<Compile Update="CustomMainForm.Designer.cs" DependentUpon="CustomMainForm.cs" />
</ItemGroup>
</Project>

View File

@ -1 +1 @@
../.build_from_cwd_debug.sh
../.build_net48_from_cwd_debug.sh

View File

@ -1 +1 @@
../.build_from_cwd_release.sh
../.build_net48_from_cwd_release.sh

View File

@ -0,0 +1,27 @@
<Project>
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
<Reference Include="System.Windows.Forms" />
<Reference Include="BizHawk.Client.ApiHawk"
HintPath="$(ProjectDir)../../output/BizHawk.Client.ApiHawk.dll"
Private="true" />
<Reference Include="BizHawk.Client.Common"
HintPath="$(ProjectDir)../../output/BizHawk.Client.Common.dll"
Private="true" />
<Reference Include="BizHawk.Common"
HintPath="$(ProjectDir)../../output/BizHawk.Common.dll"
Private="true" />
<Reference Include="BizHawk.Emulation.Common"
HintPath="$(ProjectDir)../../output/BizHawk.Emulation.Common.dll"
Private="true" />
<Reference Include="BizHawk.Emulation.Cores"
HintPath="$(ProjectDir)../../output/BizHawk.Emulation.Cores.dll"
Private="true" />
<Reference Include="BizHawk.Emulation.DiscSystem"
HintPath="$(ProjectDir)../../output/BizHawk.Emulation.DiscSystem.dll"
Private="true" />
</ItemGroup>
</Project>