Initial commit: Complete open-source Decal rebuild
All 5 phases of the open-source Decal rebuild: Phase 1: 14 decompiled .NET projects (Interop.*, Adapter, FileService, DecalUtil) Phase 2: 10 native DLLs rewritten as C# COM servers with matching GUIDs - DecalDat, DHS, SpellFilter, DecalInput, DecalNet, DecalFilters - Decal.Core, DecalControls, DecalRender, D3DService Phase 3: C++ shims for Inject.DLL (D3D9 hooking) and LauncherHook.DLL Phase 4: DenAgent WinForms tray application Phase 5: WiX installer and build script 25 C# projects building with 0 errors. Native C++ projects require VS 2022 + Windows SDK (x86). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
d1442e3747
1382 changed files with 170725 additions and 0 deletions
142
Managed/Decal.DecalFilters/CharacterStatsImpl.cs
Normal file
142
Managed/Decal.DecalFilters/CharacterStatsImpl.cs
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using Decal.Interop.Filters;
|
||||
using Decal.Interop.Net;
|
||||
|
||||
namespace Decal.DecalFilters
|
||||
{
|
||||
[ComVisible(true)]
|
||||
[Guid("4540C969-08D1-46BF-97AD-6B19D3C10BEE")]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[ComSourceInterfaces("Decal.Interop.Filters.ICharacterStatsEvents\0\0")]
|
||||
[ProgId("DecalFilters.CharacterStats")]
|
||||
public class CharacterStatsImpl : ICharacterStats, INetworkFilter2
|
||||
{
|
||||
// COM events
|
||||
public event ICharacterStatsEvents_LoginEventHandler Login;
|
||||
public event ICharacterStatsEvents_Spellbook_AddEventHandler Spellbook_Add;
|
||||
public event ICharacterStatsEvents_Spellbook_DeleteEventHandler Spellbook_Delete;
|
||||
public event ICharacterStatsEvents_LoginCompleteEventHandler LoginComplete;
|
||||
public event ICharacterStatsEvents_ActionCompleteEventHandler ActionComplete;
|
||||
public event ICharacterStatsEvents_StatusMessageEventHandler StatusMessage;
|
||||
public event ICharacterStatsEvents_DeathEventHandler Death;
|
||||
public event ICharacterStatsEvents_ChangePortalModeEventHandler ChangePortalMode;
|
||||
public event ICharacterStatsEvents_ChangeEnchantmentsEventHandler ChangeEnchantments;
|
||||
public event ICharacterStatsEvents_ChangePlayerEventHandler ChangePlayer;
|
||||
public event ICharacterStatsEvents_ChangeVitalEventHandler ChangeVital;
|
||||
public event ICharacterStatsEvents_ChangeXPSEventHandler ChangeXPS;
|
||||
public event ICharacterStatsEvents_ChangeFellowshipEventHandler ChangeFellowship;
|
||||
public event ICharacterStatsEvents_LogoffEventHandler Logoff;
|
||||
public event ICharacterStatsEvents_CastSpellEventHandler CastSpell;
|
||||
public event ICharacterStatsEvents_ChangeShortcutEventHandler ChangeShortcut;
|
||||
public event ICharacterStatsEvents_ChangeSpellbarEventHandler ChangeSpellbar;
|
||||
public event ICharacterStatsEvents_ChangeSettingsEventHandler ChangeSettings;
|
||||
public event ICharacterStatsEvents_ChangeSettingFlagsEventHandler ChangeSettingFlags;
|
||||
public event ICharacterStatsEvents_ChangeOptionEventHandler ChangeOption;
|
||||
|
||||
// State
|
||||
private int _character;
|
||||
private int _level, _rank, _skillPoints;
|
||||
private int _totalExp, _unassignedExp;
|
||||
private long _totalXP64, _unassignedXP64;
|
||||
private string _server = "", _name = "", _race = "", _gender = "", _classTemplate = "";
|
||||
private string _accountName = "";
|
||||
private int _health, _stamina, _mana;
|
||||
private int _birth, _age, _deaths;
|
||||
private int _followers, _monarchFollowers, _vassalCount;
|
||||
private int _loginStatus, _serverPopulation, _accountCharCount;
|
||||
private int _burdenUnits, _burden, _vitae;
|
||||
private int _characterOptions, _characterOptionFlags, _quickslots;
|
||||
private uint _xpToNextLevel;
|
||||
private readonly List<int> _spellbook = new List<int>();
|
||||
private readonly List<int> _augmentations = new List<int>();
|
||||
|
||||
// ICharacterStats
|
||||
public int Character => _character;
|
||||
public int Level => _level;
|
||||
public int Rank => _rank;
|
||||
public int TotalExp => _totalExp;
|
||||
public int UnassignedExp => _unassignedExp;
|
||||
public int SkillPoints => _skillPoints;
|
||||
public string Server => _server;
|
||||
public string Name => _name;
|
||||
public string Race => _race;
|
||||
public string Gender => _gender;
|
||||
public string ClassTemplate => _classTemplate;
|
||||
|
||||
public int AttributeCount => 6;
|
||||
public int SkillCount => 39;
|
||||
public int VitalCount => 3;
|
||||
|
||||
// Parameterized properties
|
||||
public AttributeInfo Attribute => null;
|
||||
public SkillInfo Skill => null;
|
||||
public SkillInfo Vital => null;
|
||||
|
||||
public int SpellLearned => _spellbook.Count;
|
||||
public int TotalSpells => _spellbook.Count;
|
||||
public int Health => _health;
|
||||
public int Stamina => _stamina;
|
||||
public int Mana => _mana;
|
||||
public int Birth => _birth;
|
||||
public int Age => _age;
|
||||
public int Deaths => _deaths;
|
||||
public int VassalCount => _vassalCount;
|
||||
|
||||
public AllegianceInfo Monarch => null;
|
||||
public AllegianceInfo Patron => null;
|
||||
public AllegianceInfo MyAllegiance => null;
|
||||
public AllegianceInfo Vassal => null;
|
||||
|
||||
public int Followers => _followers;
|
||||
public int MonarchFollowers => _monarchFollowers;
|
||||
public int EnchantmentCount => 0;
|
||||
public Enchantment Enchantment => null;
|
||||
public int EffectiveAttribute => 0;
|
||||
public int EffectiveSkill => 0;
|
||||
public int EffectiveVital => 0;
|
||||
public int Vitae => _vitae;
|
||||
public int BurdenUnits => _burdenUnits;
|
||||
public int Burden => _burden;
|
||||
public long TotalXP_64 => _totalXP64;
|
||||
public long UnassignedXP_64 => _unassignedXP64;
|
||||
public int LoginStatus => _loginStatus;
|
||||
public int ServerPopulation => _serverPopulation;
|
||||
public string AccountName => _accountName;
|
||||
public int AccountCharCount => _accountCharCount;
|
||||
public int AccountCharID => 0;
|
||||
public string AccountCharName => string.Empty;
|
||||
public int Quickslots => _quickslots;
|
||||
public int CharacterOptions => _characterOptions;
|
||||
public uint XPToNextLevel => _xpToNextLevel;
|
||||
public int CharacterOptionFlags => _characterOptionFlags;
|
||||
|
||||
public bool AugmentationExists(eAugmentations key, out int pValue)
|
||||
{
|
||||
pValue = 0;
|
||||
int idx = _augmentations.IndexOf((int)key);
|
||||
if (idx >= 0) { pValue = 1; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
public int SpellBarCount(int barNumber) => 0;
|
||||
public int SpellBar(int barNumber, int index) => 0;
|
||||
public int AugmentationCount() => _augmentations.Count;
|
||||
public int Augmentation(int index) => index >= 0 && index < _augmentations.Count ? _augmentations[index] : 0;
|
||||
public int[] SpellbookArray => _spellbook.ToArray();
|
||||
public int[] AugmentationArray => _augmentations.ToArray();
|
||||
public int[] SpellBarArray(int barNumber) => Array.Empty<int>();
|
||||
|
||||
// INetworkFilter2
|
||||
public void Initialize(NetService pService) { }
|
||||
public void Terminate() { }
|
||||
|
||||
public void DispatchServer(IMessage2 Message)
|
||||
{
|
||||
// Process character stat updates from network messages
|
||||
}
|
||||
|
||||
public void DispatchClient(IMessage2 Message) { }
|
||||
}
|
||||
}
|
||||
11
Managed/Decal.DecalFilters/Decal.DecalFilters.csproj
Normal file
11
Managed/Decal.DecalFilters/Decal.DecalFilters.csproj
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<AssemblyName>Decal.DecalFilters</AssemblyName>
|
||||
<RootNamespace>Decal.DecalFilters</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Decal.Interop.Core\Decal.Interop.Core.csproj" />
|
||||
<ProjectReference Include="..\Decal.Interop.Filters\Decal.Interop.Filters.csproj" />
|
||||
<ProjectReference Include="..\Decal.Interop.Net\Decal.Interop.Net.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
54
Managed/Decal.DecalFilters/EchoFilterImpl.cs
Normal file
54
Managed/Decal.DecalFilters/EchoFilterImpl.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using Decal.Interop.Filters;
|
||||
using Decal.Interop.Net;
|
||||
|
||||
namespace Decal.DecalFilters
|
||||
{
|
||||
[ComVisible(true)]
|
||||
[Guid("8C2FA400-315D-41DE-B063-D6EF04F12E1F")]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[ComSourceInterfaces("Decal.Interop.Filters.IEchoSink\0\0")]
|
||||
[ProgId("DecalFilters.EchoFilter")]
|
||||
public class EchoFilterImpl : IEcho, INetworkFilter2
|
||||
{
|
||||
public event IEchoSink_EchoMessageEventHandler EchoMessage;
|
||||
|
||||
public void Initialize(NetService pService) { }
|
||||
public void Terminate() { }
|
||||
|
||||
public void DispatchServer(IMessage2 Message)
|
||||
{
|
||||
// V1 echo passes IMessage, not IMessage2
|
||||
EchoMessage?.Invoke((IMessage)Message);
|
||||
}
|
||||
|
||||
public void DispatchClient(IMessage2 Message)
|
||||
{
|
||||
EchoMessage?.Invoke((IMessage)Message);
|
||||
}
|
||||
}
|
||||
|
||||
[ComVisible(true)]
|
||||
[Guid("34239EAD-6317-4c40-A405-193BA5232DD8")]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[ComSourceInterfaces("Decal.Interop.Filters.IEchoSink2\0\0")]
|
||||
[ProgId("DecalFilters.EchoFilter2")]
|
||||
public class EchoFilter2Impl : IEcho2, INetworkFilter2
|
||||
{
|
||||
public event IEchoSink2_EchoServerEventHandler EchoServer;
|
||||
public event IEchoSink2_EchoClientEventHandler EchoClient;
|
||||
|
||||
public void Initialize(NetService pService) { }
|
||||
public void Terminate() { }
|
||||
|
||||
public void DispatchServer(IMessage2 Message)
|
||||
{
|
||||
EchoServer?.Invoke(Message);
|
||||
}
|
||||
|
||||
public void DispatchClient(IMessage2 Message)
|
||||
{
|
||||
EchoClient?.Invoke(Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Managed/Decal.DecalFilters/PrefilterImpl.cs
Normal file
31
Managed/Decal.DecalFilters/PrefilterImpl.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using Decal.Interop.Filters;
|
||||
using Decal.Interop.Net;
|
||||
|
||||
namespace Decal.DecalFilters
|
||||
{
|
||||
[ComVisible(true)]
|
||||
[Guid("443D4A68-5422-4E0C-9460-973F8FBDB190")]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[ComSourceInterfaces("Decal.Interop.Filters.IPrefilterEvents\0\0")]
|
||||
[ProgId("DecalFilters.Prefilter")]
|
||||
public class PrefilterImpl : IPrefilter, INetworkFilter2
|
||||
{
|
||||
public event IPrefilterEvents_EventEventHandler Event;
|
||||
|
||||
// IPrefilter is empty
|
||||
|
||||
public void Initialize(NetService pService) { }
|
||||
public void Terminate() { }
|
||||
|
||||
public void DispatchServer(IMessage2 Message)
|
||||
{
|
||||
Event?.Invoke(Message.Type, (IMessage)Message);
|
||||
}
|
||||
|
||||
public void DispatchClient(IMessage2 Message)
|
||||
{
|
||||
Event?.Invoke(Message.Type, (IMessage)Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
68
Managed/Decal.DecalFilters/VendorImpl.cs
Normal file
68
Managed/Decal.DecalFilters/VendorImpl.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using Decal.Interop.Filters;
|
||||
|
||||
namespace Decal.DecalFilters
|
||||
{
|
||||
[ComVisible(true)]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
public class VendorImpl : IVendor
|
||||
{
|
||||
private readonly List<WorldObjectImpl> _items = new List<WorldObjectImpl>();
|
||||
private int _index = -1;
|
||||
|
||||
public int MerchantID { get; internal set; }
|
||||
public int BuyCategories { get; internal set; }
|
||||
public int BuyValue { get; internal set; }
|
||||
public float BuyRate { get; internal set; }
|
||||
public float SellRate { get; internal set; }
|
||||
public int Count => _items.Count;
|
||||
public int Quantity => _items.Count;
|
||||
|
||||
public void Reset() => _index = -1;
|
||||
|
||||
public bool Next(ref WorldObject ppObject)
|
||||
{
|
||||
_index++;
|
||||
if (_index < _items.Count)
|
||||
{
|
||||
ppObject = (WorldObject)(object)_items[_index];
|
||||
return true;
|
||||
}
|
||||
ppObject = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Pop() { }
|
||||
public void ByAll() => _index = -1;
|
||||
public void ByName(string strName) { }
|
||||
public void ByNameSubstring(string strSubstring) { }
|
||||
public void ByObjectClass(eObjectClass Class) { }
|
||||
public void ByCategory(int nCategory) { }
|
||||
|
||||
public WorldObject GetByID(int pObjectId)
|
||||
{
|
||||
foreach (var item in _items)
|
||||
if (item.GUID == pObjectId) return (WorldObject)(object)item;
|
||||
return null;
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
_index = -1;
|
||||
return new VendorEnumerator(this);
|
||||
}
|
||||
|
||||
private class VendorEnumerator : IEnumerator
|
||||
{
|
||||
private readonly VendorImpl _vendor;
|
||||
public VendorEnumerator(VendorImpl v) { _vendor = v; }
|
||||
public object Current => _vendor._index >= 0 && _vendor._index < _vendor._items.Count
|
||||
? _vendor._items[_vendor._index] : null;
|
||||
public bool MoveNext() { _vendor._index++; return _vendor._index < _vendor._items.Count; }
|
||||
public void Reset() => _vendor._index = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
149
Managed/Decal.DecalFilters/WorldImpl.cs
Normal file
149
Managed/Decal.DecalFilters/WorldImpl.cs
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using Decal.Interop.Core;
|
||||
using Decal.Interop.Filters;
|
||||
using Decal.Interop.Net;
|
||||
|
||||
namespace Decal.DecalFilters
|
||||
{
|
||||
[ComVisible(true)]
|
||||
[Guid("53092D1B-F0B0-46FF-BF11-8F031EC9B137")]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[ComSourceInterfaces("Decal.Interop.Filters.IWorldEvents\0\0")]
|
||||
[ProgId("DecalFilters.World")]
|
||||
public class WorldImpl : IWorld, INetworkFilter2
|
||||
{
|
||||
private readonly Dictionary<int, WorldObjectImpl> _objects = new Dictionary<int, WorldObjectImpl>();
|
||||
private readonly VendorImpl _vendor = new VendorImpl();
|
||||
|
||||
// COM events
|
||||
public event IWorldEvents_CreateObjectEventHandler CreateObject;
|
||||
public event IWorldEvents_ReleaseObjectEventHandler ReleaseObject;
|
||||
public event IWorldEvents_ChangeObjectEventHandler ChangeObject;
|
||||
public event IWorldEvents_MoveObjectEventHandler MoveObject;
|
||||
public event IWorldEvents_ReleaseDoneEventHandler ReleaseDone;
|
||||
public event IWorldEvents_EnterTradeEventHandler EnterTrade;
|
||||
public event IWorldEvents_EndTradeEventHandler EndTrade;
|
||||
public event IWorldEvents_AddTradeItemEventHandler AddTradeItem;
|
||||
public event IWorldEvents_AcceptTradeEventHandler AcceptTrade;
|
||||
public event IWorldEvents_DeclineTradeEventHandler DeclineTrade;
|
||||
public event IWorldEvents_ResetTradeEventHandler ResetTrade;
|
||||
public event IWorldEvents_FailToAddTradeItemEventHandler FailToAddTradeItem;
|
||||
public event IWorldEvents_FailToCompleteTradeEventHandler FailToCompleteTrade;
|
||||
public event IWorldEvents_ApproachVendorEventHandler ApproachVendor;
|
||||
|
||||
// IWorld indexer - default property [DispId(0)]
|
||||
public WorldObject this[int GUID]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_objects.TryGetValue(GUID, out var obj))
|
||||
return (WorldObject)(object)obj;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Parameterized properties - returned as iterators
|
||||
public WorldIterator ByName => (WorldIterator)(object)new WorldIteratorImpl(this);
|
||||
public WorldIterator All
|
||||
{
|
||||
get
|
||||
{
|
||||
var iter = new WorldIteratorImpl(this);
|
||||
iter.ByAll();
|
||||
return (WorldIterator)(object)iter;
|
||||
}
|
||||
}
|
||||
public WorldIterator ByObjectClass => (WorldIterator)(object)new WorldIteratorImpl(this);
|
||||
public WorldIterator ByNameSubstring => (WorldIterator)(object)new WorldIteratorImpl(this);
|
||||
public WorldIterator ByContainer => (WorldIterator)(object)new WorldIteratorImpl(this);
|
||||
public WorldIterator Inventory
|
||||
{
|
||||
get
|
||||
{
|
||||
var iter = new WorldIteratorImpl(this);
|
||||
iter.ByInventory();
|
||||
return (WorldIterator)(object)iter;
|
||||
}
|
||||
}
|
||||
public WorldIterator ByOwner => (WorldIterator)(object)new WorldIteratorImpl(this);
|
||||
public WorldIterator Landscape
|
||||
{
|
||||
get
|
||||
{
|
||||
var iter = new WorldIteratorImpl(this);
|
||||
iter.ByLandscape();
|
||||
return (WorldIterator)(object)iter;
|
||||
}
|
||||
}
|
||||
public int NumObjectClasses => 40; // eObjectClass has ~40 values
|
||||
public WorldIterator ByCategory => (WorldIterator)(object)new WorldIteratorImpl(this);
|
||||
|
||||
public double Distance2D(int GUID1, int GUID2) => 0;
|
||||
public double Distance3D(int GUID1, int GUID2) => 0;
|
||||
|
||||
public Vendor Vendor => (Vendor)(object)_vendor;
|
||||
|
||||
// INetworkFilter2
|
||||
public void Initialize(NetService pService) { }
|
||||
public void Terminate() { _objects.Clear(); }
|
||||
|
||||
public void DispatchServer(IMessage2 Message)
|
||||
{
|
||||
int type = Message.Type;
|
||||
switch (type)
|
||||
{
|
||||
case unchecked((int)0xF745): OnCreateObject(Message); break;
|
||||
case unchecked((int)0xF747): OnDeleteObject(Message); break;
|
||||
case unchecked((int)0xF748): OnUpdateObject(Message); break;
|
||||
case unchecked((int)0xF749): OnMoveObject(Message); break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DispatchClient(IMessage2 Message) { }
|
||||
|
||||
private void OnCreateObject(IMessage2 msg)
|
||||
{
|
||||
byte[] raw = msg.RawData;
|
||||
if (raw == null || raw.Length < 8) return;
|
||||
int objectId = BitConverter.ToInt32(raw, 4);
|
||||
var obj = new WorldObjectImpl { GUID = objectId };
|
||||
_objects[objectId] = obj;
|
||||
CreateObject?.Invoke((WorldObject)(object)obj);
|
||||
}
|
||||
|
||||
private void OnDeleteObject(IMessage2 msg)
|
||||
{
|
||||
byte[] raw = msg.RawData;
|
||||
if (raw == null || raw.Length < 8) return;
|
||||
int objectId = BitConverter.ToInt32(raw, 4);
|
||||
if (_objects.TryGetValue(objectId, out var obj))
|
||||
{
|
||||
ReleaseObject?.Invoke((WorldObject)(object)obj);
|
||||
_objects.Remove(objectId);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUpdateObject(IMessage2 msg)
|
||||
{
|
||||
byte[] raw = msg.RawData;
|
||||
if (raw == null || raw.Length < 8) return;
|
||||
int objectId = BitConverter.ToInt32(raw, 4);
|
||||
if (_objects.TryGetValue(objectId, out var obj))
|
||||
ChangeObject?.Invoke((WorldObject)(object)obj, WorldChangeType.wevtSizeChange);
|
||||
}
|
||||
|
||||
private void OnMoveObject(IMessage2 msg)
|
||||
{
|
||||
byte[] raw = msg.RawData;
|
||||
if (raw == null || raw.Length < 8) return;
|
||||
int objectId = BitConverter.ToInt32(raw, 4);
|
||||
if (_objects.TryGetValue(objectId, out var obj))
|
||||
MoveObject?.Invoke((WorldObject)(object)obj);
|
||||
}
|
||||
|
||||
internal List<WorldObjectImpl> GetAllObjects() => new List<WorldObjectImpl>(_objects.Values);
|
||||
internal WorldObjectImpl GetObject(int id) { _objects.TryGetValue(id, out var o); return o; }
|
||||
}
|
||||
}
|
||||
160
Managed/Decal.DecalFilters/WorldIteratorImpl.cs
Normal file
160
Managed/Decal.DecalFilters/WorldIteratorImpl.cs
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Decal.Interop.Filters;
|
||||
|
||||
namespace Decal.DecalFilters
|
||||
{
|
||||
[ComVisible(true)]
|
||||
[Guid("2681B113-294E-4ABF-B543-624194846BE1")]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[ProgId("DecalFilters.WorldIterator")]
|
||||
public class WorldIteratorImpl : IWorldIterator
|
||||
{
|
||||
private readonly WorldImpl _world;
|
||||
private List<WorldObjectImpl> _filtered;
|
||||
private int _index = -1;
|
||||
private readonly List<Func<WorldObjectImpl, bool>> _filters = new List<Func<WorldObjectImpl, bool>>();
|
||||
|
||||
internal WorldIteratorImpl(WorldImpl world)
|
||||
{
|
||||
_world = world;
|
||||
ApplyFilters();
|
||||
}
|
||||
|
||||
public WorldObject Next_Old
|
||||
{
|
||||
get
|
||||
{
|
||||
_index++;
|
||||
return (_index < _filtered.Count)
|
||||
? (WorldObject)(object)_filtered[_index]
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset() => _index = -1;
|
||||
|
||||
public int Count => _filtered?.Count ?? 0;
|
||||
|
||||
public bool Next(ref WorldObject ppObject)
|
||||
{
|
||||
_index++;
|
||||
if (_index < _filtered.Count)
|
||||
{
|
||||
ppObject = (WorldObject)(object)_filtered[_index];
|
||||
return true;
|
||||
}
|
||||
ppObject = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Pop()
|
||||
{
|
||||
if (_filters.Count > 0)
|
||||
{
|
||||
_filters.RemoveAt(_filters.Count - 1);
|
||||
ApplyFilters();
|
||||
}
|
||||
}
|
||||
|
||||
public void ByName(string strName)
|
||||
{
|
||||
_filters.Add(o => string.Equals(o.Name, strName, StringComparison.OrdinalIgnoreCase));
|
||||
ApplyFilters();
|
||||
}
|
||||
|
||||
public void ByNameSubstring(string strSubstring)
|
||||
{
|
||||
_filters.Add(o => o.Name != null && o.Name.IndexOf(strSubstring, StringComparison.OrdinalIgnoreCase) >= 0);
|
||||
ApplyFilters();
|
||||
}
|
||||
|
||||
public void ByObjectClass(eObjectClass Class)
|
||||
{
|
||||
_filters.Add(o => o.ObjectClass == Class);
|
||||
ApplyFilters();
|
||||
}
|
||||
|
||||
public void ByAll()
|
||||
{
|
||||
_filters.Clear();
|
||||
ApplyFilters();
|
||||
}
|
||||
|
||||
public void ByInventory()
|
||||
{
|
||||
_filters.Add(o => o.Container != 0);
|
||||
ApplyFilters();
|
||||
}
|
||||
|
||||
public void ByContainer(int nContainer)
|
||||
{
|
||||
_filters.Add(o => o.Container == nContainer);
|
||||
ApplyFilters();
|
||||
}
|
||||
|
||||
public int Quantity
|
||||
{
|
||||
get
|
||||
{
|
||||
int total = 0;
|
||||
foreach (var obj in _filtered)
|
||||
total += Math.Max(1, obj.Longs(LongValueKey.keyStackCount, 1));
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
public void ByOwner(int nOwner)
|
||||
{
|
||||
_filters.Add(o => o.Longs(LongValueKey.keyContainer) == nOwner);
|
||||
ApplyFilters();
|
||||
}
|
||||
|
||||
public void ByLandscape()
|
||||
{
|
||||
_filters.Add(o => o.Container == 0);
|
||||
ApplyFilters();
|
||||
}
|
||||
|
||||
public void ByCategory(int nCategory)
|
||||
{
|
||||
_filters.Add(o => o.Category == nCategory);
|
||||
ApplyFilters();
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
Reset();
|
||||
return new WorldIteratorEnumerator(this);
|
||||
}
|
||||
|
||||
private void ApplyFilters()
|
||||
{
|
||||
var all = _world.GetAllObjects();
|
||||
_filtered = all.Where(o =>
|
||||
{
|
||||
foreach (var f in _filters)
|
||||
if (!f(o)) return false;
|
||||
return true;
|
||||
}).ToList();
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
private class WorldIteratorEnumerator : IEnumerator
|
||||
{
|
||||
private readonly WorldIteratorImpl _iter;
|
||||
public WorldIteratorEnumerator(WorldIteratorImpl iter) { _iter = iter; }
|
||||
public object Current => _iter._index >= 0 && _iter._index < _iter._filtered.Count
|
||||
? _iter._filtered[_iter._index] : null;
|
||||
public bool MoveNext()
|
||||
{
|
||||
_iter._index++;
|
||||
return _iter._index < _iter._filtered.Count;
|
||||
}
|
||||
public void Reset() => _iter._index = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
139
Managed/Decal.DecalFilters/WorldObjectImpl.cs
Normal file
139
Managed/Decal.DecalFilters/WorldObjectImpl.cs
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using Decal.Interop.Filters;
|
||||
|
||||
namespace Decal.DecalFilters
|
||||
{
|
||||
[ComVisible(true)]
|
||||
[Guid("50A7E9EC-AB12-4484-9C28-C2A39274A636")]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[ProgId("DecalFilters.WorldObject")]
|
||||
public class WorldObjectImpl : IWorldObject
|
||||
{
|
||||
private readonly Dictionary<int, int> _longs = new Dictionary<int, int>();
|
||||
private readonly Dictionary<int, double> _doubles = new Dictionary<int, double>();
|
||||
private readonly Dictionary<int, bool> _bools = new Dictionary<int, bool>();
|
||||
private readonly Dictionary<int, string> _strings = new Dictionary<int, string>();
|
||||
private readonly List<int> _spells = new List<int>();
|
||||
private readonly List<int> _activeSpells = new List<int>();
|
||||
|
||||
// Position data
|
||||
private double _x, _y, _z;
|
||||
private double _ow, _ox, _oy, _oz;
|
||||
private int _landcell;
|
||||
|
||||
public int GUID { get; internal set; }
|
||||
public string Name { get; internal set; } = string.Empty;
|
||||
public eObjectClass ObjectClass { get; internal set; }
|
||||
public bool HasIdData { get; internal set; }
|
||||
public int LastIdTime { get; internal set; }
|
||||
public int PhysicsDataFlags { get; internal set; }
|
||||
public int GameDataFlags1 { get; internal set; }
|
||||
public int Type { get; internal set; }
|
||||
public int Icon { get; internal set; }
|
||||
public int Category { get; internal set; }
|
||||
public int Behavior { get; internal set; }
|
||||
public int Container { get; internal set; }
|
||||
|
||||
public bool Offset(out double x, out double y, out double z)
|
||||
{
|
||||
x = _x; y = _y; z = _z;
|
||||
return _landcell != 0;
|
||||
}
|
||||
|
||||
public bool Coordinates(ref double NorthSouth, ref double EastWest)
|
||||
{
|
||||
// Convert raw coordinates to map coordinates
|
||||
NorthSouth = _y; EastWest = _x;
|
||||
return _landcell != 0;
|
||||
}
|
||||
|
||||
public bool RawCoordinates(ref double pX, ref double pY, ref double pZ)
|
||||
{
|
||||
pX = _x; pY = _y; pZ = _z;
|
||||
return _landcell != 0;
|
||||
}
|
||||
|
||||
public bool Orientation(out double w, out double x, out double y, out double z)
|
||||
{
|
||||
w = _ow; x = _ox; y = _oy; z = _oz;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int Longs(LongValueKey index, int defVal = 0) =>
|
||||
_longs.TryGetValue((int)index, out int v) ? v : defVal;
|
||||
|
||||
public double Doubles(DoubleValueKey index, double defVal = 0.0) =>
|
||||
_doubles.TryGetValue((int)index, out double v) ? v : defVal;
|
||||
|
||||
public bool Bools(BoolValueKey index, bool defVal = false) =>
|
||||
_bools.TryGetValue((int)index, out bool v) ? v : defVal;
|
||||
|
||||
public string Strings(StringValueKey index, string defVal = "") =>
|
||||
_strings.TryGetValue((int)index, out string v) ? v : defVal;
|
||||
|
||||
public bool LongExists(LongValueKey index, out int pValue) =>
|
||||
_longs.TryGetValue((int)index, out pValue);
|
||||
|
||||
public bool DoubleExists(DoubleValueKey index, out double pValue) =>
|
||||
_doubles.TryGetValue((int)index, out pValue);
|
||||
|
||||
public bool BoolExists(BoolValueKey index, out bool pValue) =>
|
||||
_bools.TryGetValue((int)index, out pValue);
|
||||
|
||||
public bool StringExists(StringValueKey index, out string pValue) =>
|
||||
_strings.TryGetValue((int)index, out pValue);
|
||||
|
||||
public int Spell(int index) => index >= 0 && index < _spells.Count ? _spells[index] : 0;
|
||||
public int ActiveSpell(int index) => index >= 0 && index < _activeSpells.Count ? _activeSpells[index] : 0;
|
||||
|
||||
public int EnumBoolKey(int index)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var key in _bools.Keys)
|
||||
if (i++ == index) return key;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int EnumLongKey(int index)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var key in _longs.Keys)
|
||||
if (i++ == index) return key;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int EnumDoubleKey(int index)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var key in _doubles.Keys)
|
||||
if (i++ == index) return key;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int EnumStringKey(int index)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var key in _strings.Keys)
|
||||
if (i++ == index) return key;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Internal setters
|
||||
internal void SetLong(int key, int value) => _longs[key] = value;
|
||||
internal void SetDouble(int key, double value) => _doubles[key] = value;
|
||||
internal void SetBool(int key, bool value) => _bools[key] = value;
|
||||
internal void SetString(int key, string value) => _strings[key] = value;
|
||||
internal void SetPosition(double x, double y, double z, int landcell)
|
||||
{
|
||||
_x = x; _y = y; _z = z; _landcell = landcell;
|
||||
}
|
||||
internal void SetOrientation(double w, double x, double y, double z)
|
||||
{
|
||||
_ow = w; _ox = x; _oy = y; _oz = z;
|
||||
}
|
||||
internal void AddSpell(int spellId) => _spells.Add(spellId);
|
||||
internal void AddActiveSpell(int spellId) => _activeSpells.Add(spellId);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue