openDecal/Managed/Decal.Adapter/Decal.Adapter.Wrappers/Vendor.cs
erik d1442e3747 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>
2026-02-08 18:27:56 +01:00

209 lines
3.9 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using Decal.Interop.Filters;
namespace Decal.Adapter.Wrappers;
public class Vendor : GenericDisposableWrapper<Decal.Interop.Filters.Vendor>, IEnumerable<WorldObject>, IEnumerable
{
public class VendorEnumerator : IEnumerator<WorldObject>, IDisposable, IEnumerator
{
private Vendor vendor;
private WorldObject current;
public WorldObject Current
{
get
{
if (current == null)
{
MoveNext();
}
return current;
}
}
object IEnumerator.Current
{
get
{
if (current == null)
{
MoveNext();
}
return current;
}
}
internal VendorEnumerator(Vendor vendor)
{
this.vendor = vendor;
}
~VendorEnumerator()
{
Dispose(userCalled: false);
}
public void Dispose()
{
Dispose(userCalled: true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool userCalled)
{
if (vendor != null)
{
Reset();
vendor = null;
}
}
public bool MoveNext()
{
Decal.Interop.Filters.WorldObject ppObject = null;
bool num = vendor.Wrapped.Next(ref ppObject);
if (num && ppObject != null)
{
current = vendor.GetCachedObject(ppObject);
}
return num;
}
public void Reset()
{
vendor.Wrapped.Reset();
}
}
private WorldFilter wf;
private DisposableObjectDictionary<int, WorldObject> objectCache;
private IEnumerator<WorldObject> oldstyleenumerator;
public int MerchantId => base.Wrapped.MerchantID;
public int MaxValue => base.Wrapped.BuyValue;
public float SellRate => base.Wrapped.SellRate;
public float BuyRate => base.Wrapped.BuyRate;
public int Categories => base.Wrapped.BuyCategories;
public int Count => base.Wrapped.Count;
public int Quantity => base.Wrapped.Quantity;
public WorldObject First
{
get
{
using IEnumerator<WorldObject> enumerator = GetEnumerator();
return enumerator.Current;
}
}
[Obsolete("Use enumerators")]
[EditorBrowsable(EditorBrowsableState.Never)]
public WorldObject Current
{
get
{
if (oldstyleenumerator == null)
{
oldstyleenumerator = GetEnumerator();
}
return oldstyleenumerator.Current;
}
}
public WorldObject this[int id]
{
get
{
WorldObject value = null;
if (!objectCache.TryGetValue(id, out value))
{
Decal.Interop.Filters.WorldObject byID = base.Wrapped.GetByID(id);
if (byID != null)
{
value = new WorldObject(byID);
objectCache.Add(value.Id, value);
}
}
return value;
}
}
public Vendor(WorldFilter wf, Decal.Interop.Filters.Vendor obj)
: base(obj)
{
this.wf = wf;
objectCache = new DisposableObjectDictionary<int, WorldObject>("Id");
}
protected override void Dispose(bool userCalled)
{
if (oldstyleenumerator != null)
{
oldstyleenumerator.Dispose();
oldstyleenumerator = null;
}
objectCache.Clear();
base.Dispose(userCalled);
}
internal WorldObject GetCachedObject(Decal.Interop.Filters.WorldObject iwo)
{
WorldObject value = null;
if (!objectCache.TryGetValue(iwo.GUID, out value))
{
value = new WorldObject(iwo);
objectCache.Add(value.Id, value);
}
return value;
}
public void SetFilter(WorldObjectCollectionFilter filter)
{
filter?.ApplyFilter(base.Wrapped);
}
[Obsolete("Use enumerators")]
[EditorBrowsable(EditorBrowsableState.Never)]
public bool MoveNext()
{
if (oldstyleenumerator == null)
{
oldstyleenumerator = GetEnumerator();
}
return oldstyleenumerator.MoveNext();
}
[Obsolete("Use enumerators")]
[EditorBrowsable(EditorBrowsableState.Never)]
public void Reset()
{
if (oldstyleenumerator == null)
{
oldstyleenumerator = GetEnumerator();
}
oldstyleenumerator.Reset();
}
public IEnumerator<WorldObject> GetEnumerator()
{
return new VendorEnumerator(this);
}
IEnumerator IEnumerable.GetEnumerator()
{
return new VendorEnumerator(this);
}
}