diff --git a/OpenDiablo2.Common/Interfaces/Data/IResourceManager.cs b/OpenDiablo2.Common/Interfaces/Data/IResourceManager.cs index ce620d35..56e68ab9 100644 --- a/OpenDiablo2.Common/Interfaces/Data/IResourceManager.cs +++ b/OpenDiablo2.Common/Interfaces/Data/IResourceManager.cs @@ -18,7 +18,7 @@ namespace OpenDiablo2.Common.Interfaces MPQFont GetMPQFont(string resourcePath); MPQDS1 GetMPQDS1(string resourcePath, LevelPreset level, LevelDetail levelDetail, LevelType levelType); MPQDT1 GetMPQDT1(string resourcePath); - Palette GetPalette(string paletteName); + Palette GetPalette(string paletteFile); MPQCOF GetPlayerAnimation(eHero hero, eWeaponClass weaponClass, eMobMode mobMode); MPQDCC GetPlayerDCC(MPQCOF.COFLayer cofLayer, eArmorType armorType, Palette palette); diff --git a/OpenDiablo2.Common/Interfaces/ICache.cs b/OpenDiablo2.Common/Interfaces/ICache.cs new file mode 100644 index 00000000..3c0e6f1a --- /dev/null +++ b/OpenDiablo2.Common/Interfaces/ICache.cs @@ -0,0 +1,39 @@ +/* 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.Runtime.Caching; + +namespace OpenDiablo2.Common.Interfaces +{ + /// + /// Provides access to the cache system. + /// + public interface ICache + { + /// + /// Gets an item from the cache. If the item does not exist, the value factory will be executed to + /// generate the value. + /// + /// The return type of the value + /// The name of the cache key, in the form of Type::X::Y::Z where + /// Type is the base type, and x/y/z are unique identifiers for the item. + /// A function that returns the correct value if it does not already exist. + /// Pass in a new policy to control how this item is handled. Typically you can leave this null. + /// The item requested + T AddOrGetExisting(string key, Func valueFactory, CacheItemPolicy cacheItemPolicy = null); + } +} diff --git a/OpenDiablo2.Common/Models/MPQFont.cs b/OpenDiablo2.Common/Models/MPQFont.cs index f13eabf4..76f0a77b 100644 --- a/OpenDiablo2.Common/Models/MPQFont.cs +++ b/OpenDiablo2.Common/Models/MPQFont.cs @@ -1,17 +1,31 @@ -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.Collections.Generic; using System.Drawing; using System.IO; -using System.Linq; using System.Text; -using System.Threading.Tasks; namespace OpenDiablo2.Common.Models { public sealed class MPQFont { - public ImageSet FontImageSet; - public Dictionary CharacterMetric = new Dictionary(); + public ImageSet FontImageSet { get; internal set; } + public Dictionary CharacterMetric { get; internal set; } = new Dictionary(); public static MPQFont LoadFromStream(Stream fontStream, Stream tableStream) { @@ -31,7 +45,7 @@ namespace OpenDiablo2.Common.Models br.ReadBytes(3); var size = new Size(br.ReadByte(), br.ReadByte()); br.ReadBytes(3); - var charCode = br.ReadByte(); + var charCode = (char)br.ReadByte(); result.CharacterMetric[charCode] = size; br.ReadBytes(5); diff --git a/OpenDiablo2.Common/OpenDiablo2.Common.csproj b/OpenDiablo2.Common/OpenDiablo2.Common.csproj index 2de7b29e..478d0935 100644 --- a/OpenDiablo2.Common/OpenDiablo2.Common.csproj +++ b/OpenDiablo2.Common/OpenDiablo2.Common.csproj @@ -45,6 +45,7 @@ + @@ -80,6 +81,7 @@ + diff --git a/OpenDiablo2.Core/AutofacModule.cs b/OpenDiablo2.Core/AutofacModule.cs index 21eb87a8..ece95c62 100644 --- a/OpenDiablo2.Core/AutofacModule.cs +++ b/OpenDiablo2.Core/AutofacModule.cs @@ -1,6 +1,21 @@ -using Autofac; +/* 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 Autofac; using OpenDiablo2.Common.Interfaces; -using OpenDiablo2.Common.Interfaces.Drawing; using OpenDiablo2.Common.Interfaces.Mobs; using OpenDiablo2.Core.GameState_; using OpenDiablo2.Core.Map_Engine; @@ -16,6 +31,7 @@ namespace OpenDiablo2.Core { log.Info("Configuring OpenDiablo2.Core service implementations."); + builder.RegisterType().As().SingleInstance(); builder.RegisterType