diff --git a/OpenDiablo2.Common/Attributes/MessageFrameAttribute.cs b/OpenDiablo2.Common/Attributes/MessageFrameAttribute.cs
index 34cac939..65a89604 100644
--- a/OpenDiablo2.Common/Attributes/MessageFrameAttribute.cs
+++ b/OpenDiablo2.Common/Attributes/MessageFrameAttribute.cs
@@ -1,18 +1,41 @@
-using System;
+/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System;
using OpenDiablo2.Common.Enums;
namespace OpenDiablo2.Common.Attributes
{
+ ///
+ /// Defines the class as a Message Frame. This is used by the client/server logic
+ /// to decide how to serialize and deserialize networking objects.
+ ///
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
public sealed class MessageFrameAttribute : Attribute
{
+ ///
+ /// The type of message frame this class represents.
+ ///
public eMessageFrameType FrameType { get; private set; }
- // This is a positional argument
- public MessageFrameAttribute(eMessageFrameType frameType)
- {
- this.FrameType = frameType;
- }
+ ///
+ /// Define this class as a message frame.
+ ///
+ /// The type of message frame this class represents.
+ public MessageFrameAttribute(eMessageFrameType frameType) => this.FrameType = frameType;
}
diff --git a/OpenDiablo2.Common/Attributes/SceneAttribute.cs b/OpenDiablo2.Common/Attributes/SceneAttribute.cs
index 97de4d1e..51f96b54 100644
--- a/OpenDiablo2.Common/Attributes/SceneAttribute.cs
+++ b/OpenDiablo2.Common/Attributes/SceneAttribute.cs
@@ -1,15 +1,39 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System;
+using OpenDiablo2.Common.Enums;
namespace OpenDiablo2.Common.Attributes
{
+ ///
+ /// Defines this class as a scene.
+ ///
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed class SceneAttribute : Attribute
{
- public SceneAttribute(string sceneName) => SceneName = sceneName;
- public string SceneName { get; }
+ ///
+ /// Defines the type of scene that this class represents.
+ ///
+ public eSceneType SceneType { get; }
+
+ ///
+ /// Defines this class as a scene type
+ ///
+ ///
+ public SceneAttribute(eSceneType sceneType) => SceneType = sceneType;
}
}
diff --git a/OpenDiablo2.Common/Enums/eSceneType.cs b/OpenDiablo2.Common/Enums/eSceneType.cs
new file mode 100644
index 00000000..eea856c7
--- /dev/null
+++ b/OpenDiablo2.Common/Enums/eSceneType.cs
@@ -0,0 +1,29 @@
+/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+namespace OpenDiablo2.Common.Enums
+{
+ ///
+ /// Defines a scene type.
+ ///
+ public enum eSceneType
+ {
+ MainMenu,
+ SelectHeroClass,
+ SelectCharacter,
+ Game
+ }
+}
diff --git a/OpenDiablo2.Common/Interfaces/ISceneManager.cs b/OpenDiablo2.Common/Interfaces/ISceneManager.cs
index e3e1cd69..c9d1da79 100644
--- a/OpenDiablo2.Common/Interfaces/ISceneManager.cs
+++ b/OpenDiablo2.Common/Interfaces/ISceneManager.cs
@@ -1,7 +1,9 @@
-namespace OpenDiablo2.Common.Interfaces
+using OpenDiablo2.Common.Enums;
+
+namespace OpenDiablo2.Common.Interfaces
{
public interface ISceneManager
{
- void ChangeScene(string sceneName);
+ void ChangeScene(eSceneType sceneType);
}
}
diff --git a/OpenDiablo2.Common/OpenDiablo2.Common.csproj b/OpenDiablo2.Common/OpenDiablo2.Common.csproj
index 8b05fbea..2de7b29e 100644
--- a/OpenDiablo2.Common/OpenDiablo2.Common.csproj
+++ b/OpenDiablo2.Common/OpenDiablo2.Common.csproj
@@ -71,6 +71,7 @@
+
diff --git a/OpenDiablo2.Core/GameEngine.cs b/OpenDiablo2.Core/GameEngine.cs
index e8034c8a..17186b6c 100644
--- a/OpenDiablo2.Core/GameEngine.cs
+++ b/OpenDiablo2.Core/GameEngine.cs
@@ -4,6 +4,7 @@ using System.Drawing;
using System.Linq;
using System.Threading;
using OpenDiablo2.Common;
+using OpenDiablo2.Common.Enums;
using OpenDiablo2.Common.Interfaces;
using OpenDiablo2.Common.Models;
@@ -16,7 +17,7 @@ namespace OpenDiablo2.Core
private readonly GlobalConfiguration globalConfig;
private readonly IMPQProvider mpqProvider;
private readonly Func getRenderWindow;
- private readonly Func getScene;
+ private readonly Func getScene;
private readonly Func getResourceManager;
private readonly Func getGameState;
@@ -33,7 +34,7 @@ namespace OpenDiablo2.Core
GlobalConfiguration globalConfig,
IMPQProvider mpqProvider,
Func getRenderWindow,
- Func getScene,
+ Func getScene,
Func getResourceManager,
Func getGameState
)
@@ -84,7 +85,7 @@ namespace OpenDiablo2.Core
var cursor = renderWindow.LoadCursor(mouseSprite, 0, new Point(0, 3));
renderWindow.MouseCursor = cursor;
- currentScene = getScene("Main Menu");
+ currentScene = getScene(eSceneType.MainMenu);
var lastTicks = renderWindow.GetTicks();
while (getRenderWindow().IsRunning)
{
@@ -135,7 +136,7 @@ namespace OpenDiablo2.Core
currentScene?.Dispose();
}
- public void ChangeScene(string sceneName)
- => nextScene = getScene(sceneName);
+ public void ChangeScene(eSceneType sceneType)
+ => nextScene = getScene(sceneType);
}
}
diff --git a/OpenDiablo2.Core/GameState/GameState.cs b/OpenDiablo2.Core/GameState/GameState.cs
index e512a51d..9a57d9c1 100644
--- a/OpenDiablo2.Core/GameState/GameState.cs
+++ b/OpenDiablo2.Core/GameState/GameState.cs
@@ -78,7 +78,7 @@ namespace OpenDiablo2.Core.GameState_
sessionManager.OnFocusOnPlayer += OnFocusOnPlayer;
mapInfo = new List();
- sceneManager.ChangeScene("Game");
+ sceneManager.ChangeScene(eSceneType.Game);
sessionManager.JoinGame(characterName, hero);
}
diff --git a/OpenDiablo2.Scenes/AutofacModule.cs b/OpenDiablo2.Scenes/AutofacModule.cs
index 8b8d80b9..11ebaf8e 100644
--- a/OpenDiablo2.Scenes/AutofacModule.cs
+++ b/OpenDiablo2.Scenes/AutofacModule.cs
@@ -19,7 +19,7 @@ namespace OpenDiablo2.Scenes
var att = type.GetCustomAttributes(true).First(x => typeof(SceneAttribute).IsAssignableFrom(x.GetType())) as SceneAttribute;
builder
.RegisterType(type)
- .Keyed(att.SceneName)
+ .Keyed(att.SceneType)
.SingleInstance();
}
}
diff --git a/OpenDiablo2.Scenes/CharacterSelection.cs b/OpenDiablo2.Scenes/CharacterSelection.cs
index 4bf53c9c..4c16c260 100644
--- a/OpenDiablo2.Scenes/CharacterSelection.cs
+++ b/OpenDiablo2.Scenes/CharacterSelection.cs
@@ -7,7 +7,7 @@ using OpenDiablo2.Common.Interfaces;
namespace OpenDiablo2.Scenes
{
- [Scene("Select Character")]
+ [Scene(eSceneType.SelectCharacter)]
public sealed class CharacterSelection : IScene
{
static readonly log4net.ILog log =
@@ -28,7 +28,7 @@ namespace OpenDiablo2.Scenes
// TODO: use strCreateNewCharacter -- need to get the text to split after 10 chars though.
createNewCharacterButton.Text = textDictionary.Translate("strCreateNewCharacter");// "Create New".ToUpper();
createNewCharacterButton.Location = new Point(33, 467);
- createNewCharacterButton.OnActivate = () => sceneManager.ChangeScene("Select Hero Class");
+ createNewCharacterButton.OnActivate = () => sceneManager.ChangeScene(eSceneType.SelectHeroClass);
deleteCharacterButton = createButton(eButtonType.Tall);
deleteCharacterButton.Text = textDictionary.Translate("strDelete");
@@ -37,7 +37,7 @@ namespace OpenDiablo2.Scenes
exitButton = createButton(eButtonType.Medium);
exitButton.Text = textDictionary.Translate("strExit");
exitButton.Location = new Point(33, 540);
- exitButton.OnActivate = () => sceneManager.ChangeScene("Main Menu");
+ exitButton.OnActivate = () => sceneManager.ChangeScene(eSceneType.MainMenu);
okButton = createButton(eButtonType.Medium);
okButton.Text = textDictionary.Translate("strOk");
diff --git a/OpenDiablo2.Scenes/Game.cs b/OpenDiablo2.Scenes/Game.cs
index 5042b09b..52be0b10 100644
--- a/OpenDiablo2.Scenes/Game.cs
+++ b/OpenDiablo2.Scenes/Game.cs
@@ -7,7 +7,7 @@ using OpenDiablo2.Common.Interfaces;
namespace OpenDiablo2.Scenes
{
- [Scene("Game")]
+ [Scene(eSceneType.Game)]
public sealed class Game : IScene
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
diff --git a/OpenDiablo2.Scenes/MainMenu.cs b/OpenDiablo2.Scenes/MainMenu.cs
index 3072ade0..f03b5d51 100644
--- a/OpenDiablo2.Scenes/MainMenu.cs
+++ b/OpenDiablo2.Scenes/MainMenu.cs
@@ -1,19 +1,14 @@
-using OpenDiablo2.Common;
+using System;
+using System.Drawing;
+using System.Linq;
+using OpenDiablo2.Common;
using OpenDiablo2.Common.Attributes;
using OpenDiablo2.Common.Enums;
using OpenDiablo2.Common.Interfaces;
-using OpenDiablo2.Common.Models;
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
namespace OpenDiablo2.Scenes
{
- [Scene("Main Menu")]
+ [Scene(eSceneType.MainMenu)]
public class MainMenu : IScene
{
static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
@@ -40,7 +35,7 @@ namespace OpenDiablo2.Scenes
ISceneManager sceneManager,
IResourceManager resourceManager,
Func createButton,
- Func getScene // Temporary until SDL load functions are sped up
+ Func getScene // Temporary until SDL load functions are sped up
)
{
this.renderWindow = renderWindow;
@@ -80,7 +75,7 @@ namespace OpenDiablo2.Scenes
var loadingSprite = renderWindow.LoadSprite(ResourcePaths.LoadingScreen, Palettes.Loading, new Point(300, 400));
// Pre-load all the scenes for now until we fix the sdl load problem
- var scenesToLoad = new string[] {"Select Hero Class" };
+ var scenesToLoad = new eSceneType[] { eSceneType.SelectHeroClass };
for (int i = 0; i < scenesToLoad.Count(); i++)
{
renderWindow.Clear();
@@ -152,7 +147,7 @@ namespace OpenDiablo2.Scenes
}
private void OnSinglePlayerClicked()
- => sceneManager.ChangeScene("Select Hero Class");
+ => sceneManager.ChangeScene(eSceneType.SelectHeroClass);
private void OnExitClicked()
{
diff --git a/OpenDiablo2.Scenes/SelectHeroClass.cs b/OpenDiablo2.Scenes/SelectHeroClass.cs
index 636f698a..4e01a726 100644
--- a/OpenDiablo2.Scenes/SelectHeroClass.cs
+++ b/OpenDiablo2.Scenes/SelectHeroClass.cs
@@ -28,7 +28,7 @@ namespace OpenDiablo2.Scenes
public Rectangle SelectionBounds = new Rectangle();
}
- [Scene("Select Hero Class")]
+ [Scene(eSceneType.SelectHeroClass)]
public sealed class SelectHeroClass : IScene
{
static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
@@ -244,7 +244,7 @@ namespace OpenDiablo2.Scenes
okButton.Enabled = false;
selectedHero = null;
- sceneManager.ChangeScene("Select Character");
+ sceneManager.ChangeScene(eSceneType.SelectCharacter);
}
public void Render()
diff --git a/OpenDiablo2.ServiceBus/AutofacModule.cs b/OpenDiablo2.ServiceBus/AutofacModule.cs
index cf214aaf..7ac4fb70 100644
--- a/OpenDiablo2.ServiceBus/AutofacModule.cs
+++ b/OpenDiablo2.ServiceBus/AutofacModule.cs
@@ -1,4 +1,20 @@
-using System;
+/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System;
using System.Linq;
using Autofac;
using OpenDiablo2.Common.Attributes;
diff --git a/OpenDiablo2.ServiceBus/SessionManager.cs b/OpenDiablo2.ServiceBus/SessionManager.cs
index 3a767644..51a644c0 100644
--- a/OpenDiablo2.ServiceBus/SessionManager.cs
+++ b/OpenDiablo2.ServiceBus/SessionManager.cs
@@ -1,4 +1,20 @@
-using System;
+/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
diff --git a/OpenDiablo2.ServiceBus/SessionServer.cs b/OpenDiablo2.ServiceBus/SessionServer.cs
index 78c266f5..e4bdbe65 100644
--- a/OpenDiablo2.ServiceBus/SessionServer.cs
+++ b/OpenDiablo2.ServiceBus/SessionServer.cs
@@ -1,5 +1,20 @@
-using System;
-using System.Diagnostics;
+/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
diff --git a/OpenDiablo2/CommandLineOptions.cs b/OpenDiablo2/CommandLineOptions.cs
index 8278be02..7bbe0994 100644
--- a/OpenDiablo2/CommandLineOptions.cs
+++ b/OpenDiablo2/CommandLineOptions.cs
@@ -1,18 +1,46 @@
-using CommandLine;
+/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using CommandLine;
namespace OpenDiablo2
{
public sealed class CommandLineOptions
{
+ ///
+ /// The root path of the data files
+ ///
[Option('p', "datapath", Required = false, HelpText = "Specifies the root data path")]
public string DataPath { get; set; }
+ ///
+ /// When true, the hardware cursor is used instead of the software one.
+ ///
[Option("hwmouse", Default = false, Required = false, HelpText = "Use the hardware mouse instead of software")]
public bool HardwareMouse { get; set; }
+ ///
+ /// When hardware cursor mode is enabled, this changes the scale of the HW cursor
+ ///
[Option("mousescale", Default = 1, Required = false, HelpText = "When hardware mouse is enabled, this defines the pixel scale of the mouse. No effect for software mode")]
public int MouseScale { get; set; }
+ ///
+ /// When true, the game runs in full screen.
+ ///
[Option('f', "fullscreen", Default = false, Required = false, HelpText = "When set, the game will start in full screen mode")]
public bool FullScreen { get; set; }
}
diff --git a/OpenDiablo2/Program.cs b/OpenDiablo2/Program.cs
index 32be7f59..80f2adaa 100644
--- a/OpenDiablo2/Program.cs
+++ b/OpenDiablo2/Program.cs
@@ -1,4 +1,20 @@
-using System;
+/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -13,11 +29,18 @@ namespace OpenDiablo2
static class Program
{
static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+
+ // We store the global configuration here so we can bind it and return it to anything that needs it.
private static GlobalConfiguration globalConfiguration;
+
static void Main(string[] args)
{
- log.Info("OpenDiablo 2: The Free and Open Source Diablo 2 clone!");
+ log.Info("OpenDiablo 2: The Free and Open Source Diablo 2 clone!\n" +
+ "This program comes with ABSOLUTELY NO WARRANTY.\n" +
+ "This is free software, and you are welcome to redistribute it\n" +
+ "under certain conditions; type `show c' for details.");
+ // Parse the command-line arguments.
Parser.Default.ParseArguments(args).WithParsed(o => globalConfiguration = new GlobalConfiguration
{
BaseDataPath = Path.GetFullPath(o.DataPath ?? Directory.GetCurrentDirectory()),
@@ -34,16 +57,20 @@ namespace OpenDiablo2
try
{
#endif
+ // Create the AutoFac DI container
var container = BuildContainer();
try
{
+ // Resolve the game engine
using (var gameEngine = container.Resolve())
{
+ // Start the game!
gameEngine.Run();
}
}
finally
{
+ // Dispose the container, disposing any instantiated objects in the process
container.Dispose();
}
@@ -67,10 +94,10 @@ namespace OpenDiablo2
{
containerBuilder.Register(x => globalConfiguration).AsSelf().SingleInstance();
- containerBuilder.Register>(c =>
+ containerBuilder.Register>(c =>
{
var componentContext = c.Resolve();
- return (sceneName) => componentContext.ResolveKeyed(sceneName);
+ return (sceneType) => componentContext.ResolveKeyed(sceneType);
});
containerBuilder.Register>(c =>