Skip to content

Commit

Permalink
Copied from private repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Qvin committed Sep 5, 2019
1 parent 55a87fd commit 278522b
Show file tree
Hide file tree
Showing 308 changed files with 73,182 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Core/AreaController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections;
using System.Diagnostics;
using System.Threading.Tasks;
using PoEMemory;
using Shared;
using Shared.Static;

namespace Exile
{
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 AreaInstance CurrentArea { get; private set; }

public void ForceRefreshArea(bool areaChangeMultiThread) {
var ingameData = TheGameState.IngameState.Data;
var clientsArea = ingameData.CurrentArea;
var curAreaHash = TheGameState.CurrentAreaHash;
CurrentArea = new AreaInstance(clientsArea, curAreaHash, ingameData.CurrentAreaLevel);
if (CurrentArea.Name.Length == 0) return;
ActionAreaChange();
}


public bool RefreshState() {
var ingameData = TheGameState.IngameState.Data;
var clientsArea = ingameData.CurrentArea;
var curAreaHash = TheGameState.CurrentAreaHash;

if (CurrentArea != null && curAreaHash == CurrentArea.Hash)
return false;

CurrentArea = new AreaInstance(clientsArea, curAreaHash, ingameData.CurrentAreaLevel);
if (CurrentArea.Name.Length == 0) return false;
ActionAreaChange();
return true;
}

//Before call areachange for plugins need wait some time because sometimes gam,e memory not ready because still loading.
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);
}
}
45 changes: 45 additions & 0 deletions Core/AreaInstance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using PoEMemory;
using SharpDX;

namespace Exile
{
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) {
Area = area;
Hash = hash;
RealLevel = realLevel;
Name = area.Name;
Act = area.Act;
IsTown = area.IsTown;
IsHideout = Name.Contains("Hideout") && !Name.Contains("Syndicate Hideout");
HasWaypoint = area.HasWaypoint || IsHideout;
}

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

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) {
var allsec = (int) timeSpent.TotalSeconds;
var secs = allsec % 60;
var mins = allsec / 60;
var hours = mins / 60;
mins = mins % 60;
return string.Format(hours > 0 ? "{0}:{1:00}:{2:00}" : "{1}:{2:00}", hours, mins, secs);
}
}
}
106 changes: 106 additions & 0 deletions Core/BaseSettingsPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Exile.PoEMemory.MemoryObjects;
using Shared;
using Shared.Interfaces;
using Shared.Static;
using Newtonsoft.Json;
using SharpDX;

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

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

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 Name { get; set; }

public int Order { get; protected set; }


public TSettings Settings => (TSettings) _Settings;

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


if (loadedFile == null)
{
_Settings = new TSettings();
_SaveSettings();
}
else
_Settings = JsonConvert.DeserializeObject<TSettings>(loadedFile, SettingsContainer.jsonSettings);

SettingsParser.Parse(_Settings, Drawers);
}

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 Dispose() => OnClose();

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 EntityIgnored(Entity Entity) { }

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

public virtual bool Initialise() => false;

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 void LogMsg(string msg) => DebugWindow.LogMsg(msg);

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

public virtual void OnPluginDestroyForHotReload() { }

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

public virtual void Render() { }

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

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

0 comments on commit 278522b

Please sign in to comment.