Use Eccs AccessHelper

master
d4vid 3 months ago
parent 0cea94de4d
commit 1878d31454

@ -1,7 +1,7 @@
ID: D4VID_ConsoleImprovements
Name: ConsoleImprovements
Author: D4VID
Version: 1.1.1
Version: 1.1.2
Priority: 0
ClientOnly: true
Dependencies:

@ -22,11 +22,7 @@ namespace ConsoleImprovements.Client {
_logger = logger;
// Get access to the rich text string inside the MessageData class
_commandInputFieldField = AccessTools.Field(typeof(Console), "CommandInputField");
if (_commandInputFieldField == null) {
_logger.Error("Cannot get field CommandInputField of Console");
return false;
}
_commandInputFieldField = Fields.getPrivate(typeof(Console), "CommandInputField");
return true;
}

@ -9,7 +9,7 @@ namespace ConsoleImprovements.Client {
public class MessageCopyPatch {
private static ILogicLogger _logger = null!;
private static MethodInfo? _removeRichTextTagsMethod;
private static FieldInfo? _dataProperty;
private static FieldInfo? _dataField;
private static FieldInfo? _messageRichTextField;
private static FieldInfo? _messageTypeField;
@ -17,36 +17,16 @@ namespace ConsoleImprovements.Client {
_logger = logger;
// Get the private RemoveRichTextTags method of Message
_removeRichTextTagsMethod = AccessTools.Method(
typeof(Message),
"RemoveRichTextTags",
new[] {typeof(string)}
);
if (_removeRichTextTagsMethod == null) {
_logger.Error("Cannot get method RemoveRichTextTags of message");
return false;
}
_removeRichTextTagsMethod = Methods.getPrivate(typeof(Message), "RemoveRichTextTags");
// Get access to the Data property of Message, which is of internal type MessageData
_dataProperty = AccessTools.Field(typeof(Message), "Data");
if (_dataProperty == null) {
_logger.Error("Cannot get field Data of message");
return false;
}
// Get access to the Data field of Message, which is of internal type MessageData
_dataField = Fields.getPrivate(typeof(Message), "Data");
// Get access to the rich text string inside the MessageData class
_messageRichTextField = AccessTools.Field(_dataProperty.FieldType, "messageRichText");
if (_messageRichTextField == null) {
_logger.Error("Cannot get field messageRichText of message data");
return false;
}
_messageRichTextField = Fields.getPublic(_dataField.FieldType, "messageRichText");
// Get access to the message type enum inside the MessageData class
_messageTypeField = AccessTools.Field(_dataProperty.FieldType, "messageType");
if (_messageTypeField == null) {
_logger.Error("Cannot get field messageRichText of message data");
return false;
}
_messageTypeField = Fields.getPublic(_dataField.FieldType, "messageType");
return true;
}
@ -60,7 +40,7 @@ namespace ConsoleImprovements.Client {
// Prefix the CopyMessageToClipboard method with this one
// ReSharper disable once InconsistentNaming
public static bool Hook(Message __instance) {
var dataInstance = _dataProperty!.GetValue(__instance);
var dataInstance = _dataField!.GetValue(__instance);
if (dataInstance == null) {
_logger.Error("Cannot get instance of MessageData");
return true; // Resume original functionality

Loading…
Cancel
Save