using System; using System.Reflection; using CLre.API.Engines; using HarmonyLib; using NetworkFramework.Shared; using Svelto.ECS; using Svelto.Obsolete.ECS; namespace CLre.API.Characters { public class Character { private bool isCurrent; private readonly CharacterEngine _characterEngine = new CharacterEngine(); private static readonly FieldInfo _AccountUtility__username = AccessTools.Field(AccessTools.TypeByName("Game.Utilities.Account.AccountUtility"), "_username"); public string Username { get { if (isCurrent) { return _AccountUtility__username.GetValue(null) as string; } return null; } } /// /// When enabled, all user flags for the current user are set to one, so they unlock all client functionality /// public bool Superuser { get => AccountUtility_GetUserFlags_Patch.superuser; set => AccountUtility_GetUserFlags_Patch.superuser = value; } public static Character Local() { Character localChar = new Character(); localChar.isCurrent = true; return localChar; } } internal class CharacterEngine : GameObsoleteEnginePostBuild { public override void Ready() { } public override IEntitiesDB entitiesDB { get; set; } public override IEntityFactory entityFactory { get; set; } public bool GetGodModeRequested() { if (entitiesDB == null) return false; // TODO cache this conversion operation // equivalent to // return DEPRECATED_SveltoExtensions.GetFirstNodeDeprecatedMethod()?.godModeRequestComponent.value Type cgmrd = AccessTools.TypeByName("Game.GodMode.ClientGodModeRequestNode"); Type igmrc = AccessTools.TypeByName("Game.GodMode.IGodModeRequestComponent"); MethodInfo cgmrdFirstNode = AccessTools.Method(typeof(DEPRECATED_SveltoExtensions), "GetFirstNoteDeprecatedMethod") .MakeGenericMethod(cgmrd); FieldInfo cgmrdIField = AccessTools.Field(cgmrd, "godModeRequestComponent"); MethodInfo igmrcReqGodMode = AccessTools.PropertyGetter(igmrc, "requestGodMode"); // op start object firstNode = cgmrdFirstNode.Invoke(null, new []{entitiesDB}); if (firstNode != null) { object godModeRequestComponent = cgmrdIField.GetValue(firstNode); ObsoleteDispatchOnSet requestGodMode = (ObsoleteDispatchOnSet)igmrcReqGodMode.Invoke(godModeRequestComponent, new object[]{}); return requestGodMode.value; } return false; } public void SetGodModeRequested(bool val) { if (entitiesDB == null) return; // TODO cache this conversion operation //DEPRECATED_SveltoExtensions.GetFirstNodeDeprecatedMethod() Type cgmrd = AccessTools.TypeByName("Game.GodMode.ClientGodModeRequestNode"); Type igmrc = AccessTools.TypeByName("Game.GodMode.IGodModeRequestComponent"); MethodInfo cgmrdFirstNode = AccessTools.Method(typeof(DEPRECATED_SveltoExtensions), "GetFirstNoteDeprecatedMethod") .MakeGenericMethod(cgmrd); FieldInfo cgmrdIField = AccessTools.Field(cgmrd, "godModeRequestComponent"); MethodInfo igmrcReqGodMode = AccessTools.PropertyGetter(igmrc, "requestGodMode"); // operation start object firstNode = cgmrdFirstNode.Invoke(null, new []{entitiesDB}); Utility.Logging.MetaLog($"firstNode is null? {firstNode == null}"); if (firstNode != null) { Utility.Logging.MetaLog($"firstNode is type {firstNode.GetType().FullName}"); object godModeRequestComponent = cgmrdIField.GetValue(firstNode); ObsoleteDispatchOnSet requestGodMode = (ObsoleteDispatchOnSet)igmrcReqGodMode.Invoke(godModeRequestComponent, new object[]{}); requestGodMode.value = val; Utility.Logging.MetaLog($"SetGodModeRequested completed successfully"); } } } }