Skip to content

Commit

Permalink
Sync with ReClass.NET code changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
KN4CK3R committed Nov 15, 2016
1 parent 32b4992 commit afc1fc9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 112 deletions.
2 changes: 1 addition & 1 deletion FrostbitePlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</Compile>
<Compile Include="WeakPtrCodeGenerator.cs" />
<Compile Include="WeakPtrNode.cs" />
<Compile Include="WeakPtrSchemaConverter.cs" />
<Compile Include="WeakPtrNodeConverter.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ReClass.NET\ReClass.NET.csproj">
Expand Down
4 changes: 2 additions & 2 deletions FrostbitePluginExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FrostbitePluginExt : Plugin

private INodeInfoReader reader;

private WeakPtrSchemaConverter converter;
private WeakPtrNodeConverter converter;
private WeakPtrCodeGenerator generator;

public override Image Icon => Properties.Resources.logo_frostbite;
Expand Down Expand Up @@ -45,7 +45,7 @@ public override bool Initialize(IPluginHost host)
host.RegisterNodeInfoReader(reader);

// Register the WeakPtr node
converter = new WeakPtrSchemaConverter();
converter = new WeakPtrNodeConverter();
generator = new WeakPtrCodeGenerator();
host.RegisterNodeType(typeof(WeakPtrNode), "Frostbite WeakPtr", Icon, converter, generator);

Expand Down
5 changes: 4 additions & 1 deletion WeakPtrNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ class WeakPtrNode : BaseReferenceNode
/// <summary>Disable the cycle check for pointer references.</summary>
public override bool PerformCycleCheck => false;

/// <summary>Creates a new instance of this class to clone it.</summary>
protected override BaseNode CreateCloneInstance() => new WeakPtrNode();

/// <summary>Called when the node was created. Creates a new class as inner node.</summary>
public override void Intialize()
{
var node = ClassManager.CreateClass();
var node = ClassNode.Create();
node.Intialize();
node.AddBytes(64);
InnerNode = node;
Expand Down
74 changes: 74 additions & 0 deletions WeakPtrNodeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Xml.Linq;
using ReClassNET.DataExchange;
using ReClassNET.Logger;
using ReClassNET.Nodes;

namespace FrostbitePlugin
{
class WeakPtrNodeConverter : ICustomNodeConverter
{
/// <summary>Name of the type used in the XML data.</summary>
private const string XmlType = "FrostBite::WeakPtr";

/// <summary>Checks if the node can be handled.</summary>
/// <param name="node">The node to check.</param>
/// <returns>True if we can handle the node, false if not.</returns>
public bool CanHandleNode(BaseNode node) => node is WeakPtrNode;

/// <summary>Checks if the element can be handled.</summary>
/// <param name="element">The element to check.</param>
/// <returns>True if we can read node, false if not.</returns>
public bool CanHandleElement(XElement element) => element.Attribute(ReClassNetFile.XmlTypeAttribute)?.Value == XmlType;

/// <summary>Creates a node from the xml element. This method gets only called if <see cref="CanHandleElement(XElement)"/> returned true.</summary>
/// <param name="element">The element to create the node from.</param>
/// <param name="parent">The parent of the node.</param>
/// <param name="classes">The list of classes which correspond to the node.</param>
/// <param name="logger">The logger used to output messages.</param>
/// <param name="node">[out] The node for the xml element.</param>
/// <returns>True if a node was created, otherwise false.</returns>
public bool TryCreateNodeFromElement(XElement element, ClassNode parent, IEnumerable<ClassNode> classes, ILogger logger, out BaseNode node)
{
node = null;

var reference = NodeUuid.FromBase64String(element.Attribute(ReClassNetFile.XmlReferenceAttribute)?.Value, false);
var innerClass = classes.Where(c => c.Uuid.Equals(reference)).FirstOrDefault();
if (innerClass == null)
{
logger.Log(LogLevel.Warning, $"Skipping node with unknown reference: {reference}");
logger.Log(LogLevel.Warning, element.ToString());

return false;
}

var weakPtrNode = new WeakPtrNode
{
Name = element.Attribute(ReClassNetFile.XmlNameAttribute)?.Value ?? string.Empty,
Comment = element.Attribute(ReClassNetFile.XmlCommentAttribute)?.Value ?? string.Empty
};
weakPtrNode.ChangeInnerNode(innerClass);

node = weakPtrNode;

return true;
}

/// <summary>Creates a xml element from the node. This method gets only called if <see cref="CanHandleNode(BaseNode node)"/> returned true.</summary>
/// <param name="node">The node to create the xml element from.</param>
/// <param name="logger">The logger used to output messages.</param>
/// <returns>The xml element for the node.</returns>
public XElement CreateElementFromNode(BaseNode node, ILogger logger)
{
return new XElement(
ReClassNetFile.XmlNodeElement,
new XAttribute(ReClassNetFile.XmlNameAttribute, node.Name ?? string.Empty),
new XAttribute(ReClassNetFile.XmlCommentAttribute, node.Comment ?? string.Empty),
new XAttribute(ReClassNetFile.XmlTypeAttribute, XmlType),
new XAttribute(ReClassNetFile.XmlReferenceAttribute, (node as WeakPtrNode).InnerNode.Uuid.ToBase64String())
);
}
}
}
108 changes: 0 additions & 108 deletions WeakPtrSchemaConverter.cs

This file was deleted.

0 comments on commit afc1fc9

Please sign in to comment.