Skip to content

Commit

Permalink
3.0.5399.19376
Browse files Browse the repository at this point in the history
added inventory info worker/settings
  • Loading branch information
Icehunter committed Oct 13, 2014
1 parent 3835a0a commit 63027bc
Show file tree
Hide file tree
Showing 17 changed files with 334 additions and 21 deletions.
1 change: 1 addition & 0 deletions FFXIVAPP.Client/FFXIVAPP.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<Compile Include="Memory\ChatEntry.cs" />
<Compile Include="Memory\ActionWorker.cs" />
<Compile Include="Memory\ActorWorker.cs" />
<Compile Include="Memory\InventoryWorker.cs" />
<Compile Include="Memory\PartyInfoWorker.cs" />
<Compile Include="Memory\TargetWorker.cs" />
<Compile Include="Memory\PlayerInfoWorker.cs" />
Expand Down
6 changes: 6 additions & 0 deletions FFXIVAPP.Client/Helpers/AppContextHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,11 @@ public void RaiseNewPartyEntries(List<PartyEntity> partyEntries)
// THIRD PARTY
PluginHost.Instance.RaiseNewPartyEntries(partyEntries);
}

public void RaiseNewInventoryEntries(List<InventoryEntity> inventoryEntities)
{
// THIRD PARTY
PluginHost.Instance.RaiseNewInventoryEntries(inventoryEntities);
}
}
}
14 changes: 14 additions & 0 deletions FFXIVAPP.Client/Initializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ internal static class Initializer
private static PlayerInfoWorker _playerInfoWorker;
private static TargetWorker _targetWorker;
private static PartyInfoWorker _partyInfoWorker;
private static InventoryWorker _inventoryWorker;

#endregion

Expand Down Expand Up @@ -662,6 +663,12 @@ public static void SetSignatures()
Value = "40??00000000000000000000000000000000000000000000000000000000????0000????000000000000DB0FC93FDB0F49416F1283??FFFFFFFF",
Offset = 206
});
AppViewModel.Instance.Signatures.Add(new Signature
{
Key = "INVENTORY",
Value = "DB0FC93FDB0F49416F1283??FFFFFFFF0000000000000000000000000000000000000000DB0FC93FDB0F49416F1283??FFFFFFFF",
Offset = 56
});
}

/// <summary>
Expand Down Expand Up @@ -756,6 +763,8 @@ public static void StartMemoryWorkers()
_targetWorker.StartScanning();
_partyInfoWorker = new PartyInfoWorker();
_partyInfoWorker.StartScanning();
_inventoryWorker = new InventoryWorker();
_inventoryWorker.StartScanning();
}

public static void UpdatePluginConstants()
Expand Down Expand Up @@ -802,6 +811,11 @@ public static void StopMemoryWorkers()
_partyInfoWorker.StopScanning();
_partyInfoWorker.Dispose();
}
if (_inventoryWorker != null)
{
_inventoryWorker.StopScanning();
_inventoryWorker.Dispose();
}
}
}
}
232 changes: 232 additions & 0 deletions FFXIVAPP.Client/Memory/InventoryWorker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
// FFXIVAPP.Client
// InventoryWorker.cs
//
// Copyright © 2007 - 2014 Ryan Wilson - All Rights Reserved
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of SyndicatedLife nor the names of its contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Timers;
using FFXIVAPP.Client.Helpers;
using FFXIVAPP.Client.Properties;
using FFXIVAPP.Common.Core.Memory;
using FFXIVAPP.Common.Core.Memory.Enums;
using Newtonsoft.Json;
using NLog;

namespace FFXIVAPP.Client.Memory
{
internal class InventoryWorker : INotifyPropertyChanged, IDisposable
{
#region Logger

private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

#endregion

#region Property Bindings

public uint InventoryPointerMap { get; set; }
public List<InventoryEntity> LastInventoryEntities { get; set; }

#endregion

#region Declarations

private readonly Timer _scanTimer;
private bool _isScanning;

#endregion

public InventoryWorker()
{
_scanTimer = new Timer(1000);
_scanTimer.Elapsed += ScanTimerElapsed;
}

#region Timer Controls

/// <summary>
/// </summary>
public void StartScanning()
{
_scanTimer.Enabled = true;
}

/// <summary>
/// </summary>
public void StopScanning()
{
_scanTimer.Enabled = false;
}

#endregion

#region Threads

public Stopwatch Stopwatch = new Stopwatch();

/// <summary>
/// </summary>
/// <param name="sender"> </param>
/// <param name="e"> </param>
private void ScanTimerElapsed(object sender, ElapsedEventArgs e)
{
if (_isScanning)
{
return;
}
_isScanning = true;
double refresh = 100;
if (Double.TryParse(Settings.Default.InventoryWorkerRefresh.ToString(CultureInfo.InvariantCulture), out refresh))
{
_scanTimer.Interval = refresh;
}
Func<bool> scannerWorker = delegate
{
if (MemoryHandler.Instance.SigScanner.Locations.ContainsKey("INVENTORY"))
{
try
{
InventoryPointerMap = MemoryHandler.Instance.GetUInt32(MemoryHandler.Instance.SigScanner.Locations["INVENTORY"]);

var inventoryEntities = new List<InventoryEntity>
{
GetItems(InventoryPointerMap, Inventory.Container.INVENTORY_1),
GetItems(InventoryPointerMap, Inventory.Container.INVENTORY_2),
GetItems(InventoryPointerMap, Inventory.Container.INVENTORY_3),
GetItems(InventoryPointerMap, Inventory.Container.INVENTORY_4),
GetItems(InventoryPointerMap, Inventory.Container.CURRENT_EQ),
GetItems(InventoryPointerMap, Inventory.Container.EXTRA_EQ),
GetItems(InventoryPointerMap, Inventory.Container.CRYSTALS),
GetItems(InventoryPointerMap, Inventory.Container.QUESTS_KI),
GetItems(InventoryPointerMap, Inventory.Container.AC_MH),
GetItems(InventoryPointerMap, Inventory.Container.AC_OH),
GetItems(InventoryPointerMap, Inventory.Container.AC_HEAD),
GetItems(InventoryPointerMap, Inventory.Container.AC_BODY),
GetItems(InventoryPointerMap, Inventory.Container.AC_HANDS),
GetItems(InventoryPointerMap, Inventory.Container.AC_BELT),
GetItems(InventoryPointerMap, Inventory.Container.AC_LEGS),
GetItems(InventoryPointerMap, Inventory.Container.AC_FEET),
GetItems(InventoryPointerMap, Inventory.Container.AC_EARRINGS),
GetItems(InventoryPointerMap, Inventory.Container.AC_NECK),
GetItems(InventoryPointerMap, Inventory.Container.AC_WRISTS),
GetItems(InventoryPointerMap, Inventory.Container.AC_RINGS),
GetItems(InventoryPointerMap, Inventory.Container.AC_SOULS)
};
var notify = false;
if (LastInventoryEntities == null)
{
LastInventoryEntities = inventoryEntities;
notify = true;
}
else
{
var hash1 = JsonConvert.SerializeObject(LastInventoryEntities)
.GetHashCode();
var hash2 = JsonConvert.SerializeObject(inventoryEntities)
.GetHashCode();
if (!hash1.Equals(hash2))
{
LastInventoryEntities = inventoryEntities;
notify = true;
}
}
if (notify)
{
AppContextHelper.Instance.RaiseNewInventoryEntries(inventoryEntities);
}
}
catch (Exception ex)
{
}
}

_isScanning = false;
return true;
};
scannerWorker.BeginInvoke(delegate { }, scannerWorker);
}

private InventoryEntity GetItems(uint address, Inventory.Container type)
{
var offset = (uint) ((int) type * 24);
var containerAddress = MemoryHandler.Instance.GetUInt32(address, offset);

var container = new InventoryEntity
{
Amount = MemoryHandler.Instance.GetByte(address, offset + 0x8),
Items = new List<ItemInfo>(),
Type = type
};

for (var ci = 0; ci < 1600; ci += 64)
{
var itemOffset = (uint) (containerAddress + ci);
var id = MemoryHandler.Instance.GetUInt32(itemOffset, 0x8);
if (id > 0)
{
container.Items.Add(new ItemInfo
{
ID = id,
Amount = MemoryHandler.Instance.GetByte(itemOffset, 0xC),
SB = MemoryHandler.Instance.GetUInt16(itemOffset, 0x10),
Durability = MemoryHandler.Instance.GetUInt16(itemOffset, 0x12),
GlamourID = MemoryHandler.Instance.GetUInt32(itemOffset, 0x30)
});
}
}

return container;
}

#endregion

#region Implementation of INotifyPropertyChanged

public event PropertyChangedEventHandler PropertyChanged = delegate { };

private void RaisePropertyChanged([CallerMemberName] string caller = "")
{
PropertyChanged(this, new PropertyChangedEventArgs(caller));
}

#endregion

#region Implementation of IDisposable

public void Dispose()
{
_scanTimer.Elapsed -= ScanTimerElapsed;
}

#endregion
}
}
12 changes: 12 additions & 0 deletions FFXIVAPP.Client/PluginHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ public void PopupMessage(string pluginName, PopupContent popupContent)

public event EventHandler<PartyEntitiesEvent> NewPartyEntries = delegate { };

public event EventHandler<InventoryEntitiesEvent> NewInventoryEntries = delegate { };

public virtual void RaiseNewConstantsEntity(ConstantsEntity e)
{
var constantsEntityEvent = new ConstantsEntityEvent(this, e);
Expand Down Expand Up @@ -330,6 +332,16 @@ public virtual void RaiseNewPartyEntries(List<PartyEntity> e)
}
}

public virtual void RaiseNewInventoryEntries(List<InventoryEntity> e)
{
var inventoryEntitiesEvent = new InventoryEntitiesEvent(this, e);
var handler = NewInventoryEntries;
if (handler != null)
{
handler(this, inventoryEntitiesEvent);
}
}

#endregion
}
}
14 changes: 13 additions & 1 deletion FFXIVAPP.Client/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions FFXIVAPP.Client/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,8 @@
<Setting Name="MonsterWorkerRefresh" Type="System.String" Scope="User">
<Value Profile="(Default)">100</Value>
</Setting>
<Setting Name="InventoryWorkerRefresh" Type="System.String" Scope="User">
<Value Profile="(Default)">1000</Value>
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit 63027bc

Please sign in to comment.