Skip to content

Commit

Permalink
Merge pull request #54 from Qvin0000/dev
Browse files Browse the repository at this point in the history
New API (Cleaup) and some fixes
  • Loading branch information
Qvin0000 authored Sep 12, 2019
2 parents 89fe115 + 9dc302d commit e8b2fe5
Show file tree
Hide file tree
Showing 309 changed files with 56,381 additions and 54,738 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*.suo
*.user
*.sln.docstates

Plugins/
# Build results
[Dd]ebug/
[Rr]elease/
Expand Down
37 changes: 21 additions & 16 deletions Core/AreaController.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
using System;
using System.Collections;
using System.Diagnostics;
using System.Threading.Tasks;
using PoEMemory;
using Shared;
using Shared.Static;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.Shared;

namespace Exile
namespace ExileCore
{
public class AreaController
{
public TheGame TheGameState { get; }
private const string areaChangeCoroutineName = "Area change";

public AreaController(TheGame theGameState) => TheGameState = theGameState;

public event Action<AreaInstance> OnAreaChange;
public AreaController(TheGame theGameState)
{
TheGameState = theGameState;
}

public TheGame TheGameState { get; }
public AreaInstance CurrentArea { get; private set; }
public event Action<AreaInstance> OnAreaChange;

public void ForceRefreshArea(bool areaChangeMultiThread) {
public void ForceRefreshArea(bool areaChangeMultiThread)
{
var ingameData = TheGameState.IngameState.Data;
var clientsArea = ingameData.CurrentArea;
var curAreaHash = TheGameState.CurrentAreaHash;
Expand All @@ -28,8 +28,8 @@ public void ForceRefreshArea(bool areaChangeMultiThread) {
ActionAreaChange();
}


public bool RefreshState() {
public bool RefreshState()
{
var ingameData = TheGameState.IngameState.Data;
var clientsArea = ingameData.CurrentArea;
var curAreaHash = TheGameState.CurrentAreaHash;
Expand All @@ -44,11 +44,16 @@ public bool RefreshState() {
}

//Before call areachange for plugins need wait some time because sometimes gam,e memory not ready because still loading.
private IEnumerator CoroutineAreaChange(bool areaChangeMultiThread) {
private IEnumerator CoroutineAreaChange(bool areaChangeMultiThread)
{
yield return new WaitFunction(() => TheGameState.IsLoading /*&& !TheGameState.InGame*/);

// yield return new WaitTime((int)(TheGameState.IngameState.CurLatency));
}

private void ActionAreaChange() => OnAreaChange?.Invoke(CurrentArea);
private void ActionAreaChange()
{
OnAreaChange?.Invoke(CurrentArea);
}
}
}
}
35 changes: 20 additions & 15 deletions Core/AreaInstance.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
using System;
using PoEMemory;
using ExileCore.PoEMemory.MemoryObjects;
using SharpDX;

namespace Exile
namespace ExileCore
{
public sealed class AreaInstance
{
public static uint CurrentHash;
public int RealLevel { get; }
public string Name { get; }
public int Act { get; }
public bool IsTown { get; }
public bool IsHideout { get; }
public bool HasWaypoint { get; }
public uint Hash { get; }
public AreaTemplate Area { get; }

public AreaInstance(AreaTemplate area, uint hash, int realLevel) {
public AreaInstance(AreaTemplate area, uint hash, int realLevel)
{
Area = area;
Hash = hash;
RealLevel = realLevel;
Expand All @@ -27,13 +20,25 @@ public AreaInstance(AreaTemplate area, uint hash, int realLevel) {
HasWaypoint = area.HasWaypoint || IsHideout;
}

public override string ToString() => $"{Name} ({RealLevel}) #{Hash}";

public int RealLevel { get; }
public string Name { get; }
public int Act { get; }
public bool IsTown { get; }
public bool IsHideout { get; }
public bool HasWaypoint { get; }
public uint Hash { get; }
public AreaTemplate Area { get; }
public string DisplayName => string.Concat(Name, " (", RealLevel, ")");
public DateTime TimeEntered { get; } = DateTime.UtcNow;
public Color AreaColorName { get; set; } = Color.Aqua;

public static string GetTimeString(TimeSpan timeSpent) {
public override string ToString()
{
return $"{Name} ({RealLevel}) #{Hash}";
}

public static string GetTimeString(TimeSpan timeSpent)
{
var allsec = (int) timeSpent.TotalSeconds;
var secs = allsec % 60;
var mins = allsec / 60;
Expand All @@ -42,4 +47,4 @@ public static string GetTimeString(TimeSpan timeSpent) {
return string.Format(hours > 0 ? "{0}:{1:00}:{2:00}" : "{1}:{2:00}", hours, mins, secs);
}
}
}
}
136 changes: 94 additions & 42 deletions Core/BaseSettingsPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,42 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Exile.PoEMemory.MemoryObjects;
using Shared;
using Shared.Interfaces;
using Shared.Static;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.Shared.Interfaces;
using Newtonsoft.Json;
using SharpDX;

namespace Exile
namespace ExileCore
{
public abstract class BaseSettingsPlugin<TSettings> : IPlugin where TSettings : ISettings, new()
{
private TSettings settings;

public BaseSettingsPlugin() {
public BaseSettingsPlugin()
{
InternalName = GetType().Namespace;
if (string.IsNullOrWhiteSpace(Name)) Name = InternalName;
Drawers = new List<ISettingsHolder>();
}

public List<ISettingsHolder> Drawers { get; }
public GameController GameController { get; private set; }
public Graphics Graphics { get; private set; }
public TSettings Settings => (TSettings) _Settings;
public ISettings _Settings { get; private set; }
public bool CanUseMultiThreading { get; protected set; }
public string Description { get; protected set; }
public string DirectoryName { get; set; }
public string DirectoryFullName { get; set; }
public List<ISettingsHolder> Drawers { get; }
public bool Force { get; protected set; }
public GameController GameController { get; private set; }
public Graphics Graphics { get; private set; }
public bool Initialized { get; set; }
public string InternalName { get; private set; }

public string InternalName { get; }
public string Name { get; set; }

public int Order { get; protected set; }


public TSettings Settings => (TSettings) _Settings;

public void _LoadSettings() {
public void _LoadSettings()
{
var loadedFile = GameController.Settings.LoadSettings(this);


if (loadedFile == null)
{
_Settings = new TSettings();
Expand All @@ -54,53 +48,111 @@ public void _LoadSettings() {
SettingsParser.Parse(_Settings, Drawers);
}

public void _SaveSettings() {
public void _SaveSettings()
{
if (_Settings == null)
throw new NullReferenceException("Plugin settings is null");

GameController.Settings.SaveSettings(this);
}

public virtual void AreaChange(AreaInstance area) { }
public virtual void AreaChange(AreaInstance area)
{
}

public virtual void Dispose() => OnClose();
public virtual void Dispose()
{
OnClose();
}

public virtual void DrawSettings() {
foreach (var drawer in Drawers) drawer.Draw();
public virtual void DrawSettings()
{
foreach (var drawer in Drawers)
{
drawer.Draw();
}
}

public virtual void EntityAdded(Entity Entity) { }
public virtual void EntityAddedAny(Entity Entity) { }
public virtual void EntityAdded(Entity Entity)
{
}

public virtual void EntityIgnored(Entity Entity) { }
public virtual void EntityAddedAny(Entity Entity)
{
}

public virtual void EntityRemoved(Entity Entity) { }
public virtual void OnLoad() { }
public virtual void OnUnload() { }
public virtual void EntityIgnored(Entity Entity)
{
}

public virtual bool Initialise() => false;
public virtual void EntityRemoved(Entity Entity)
{
}

public void LogError(string msg, float time = 1f) => DebugWindow.LogError(msg, time);
public virtual void OnLoad()
{
}

public void LogMessage(string msg, float time, Color clr) => DebugWindow.LogMsg(msg, time, clr);
public virtual void OnUnload()
{
}

public void LogMessage(string msg, float time = 1f) => DebugWindow.LogMsg(msg, time, Color.GreenYellow);
public virtual bool Initialise()
{
return false;
}

public void LogMsg(string msg) => DebugWindow.LogMsg(msg);
public void LogMsg(string msg)
{
DebugWindow.LogMsg(msg);
}

public virtual void OnClose() => _SaveSettings();
public virtual void OnClose()
{
_SaveSettings();
}

public virtual void OnPluginDestroyForHotReload() { }
public virtual void OnPluginSelectedInMenu()
{
}

public virtual void OnPluginSelectedInMenu() { }
public virtual Job Tick() => null;
public virtual Job Tick()
{
return null;
}

public virtual void Render() { }
public virtual void Render()
{
}

public void SetApi(object gameController, object graphics) => SetApi((GameController) gameController, (Graphics) graphics);
public void SetApi(object gameController, object graphics)
{
SetApi((GameController) gameController, (Graphics) graphics);
}

public void LogError(string msg, float time = 1f)
{
DebugWindow.LogError(msg, time);
}

public void LogMessage(string msg, float time, Color clr)
{
DebugWindow.LogMsg(msg, time, clr);
}

public void LogMessage(string msg, float time = 1f)
{
DebugWindow.LogMsg(msg, time, Color.GreenYellow);
}

public virtual void OnPluginDestroyForHotReload()
{
}

private void SetApi(GameController gameController, Graphics graphics) {
private void SetApi(GameController gameController, Graphics graphics)
{
GameController = gameController;
Graphics = graphics;
}
}
}
}
Loading

0 comments on commit e8b2fe5

Please sign in to comment.