Unofficial CardLife revival project, pronounced like "celery"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
4.4KB

  1. using System;
  2. using System.Reflection;
  3. using CLre.API.Engines;
  4. using HarmonyLib;
  5. using NetworkFramework.Shared;
  6. using Svelto.ECS;
  7. using Svelto.Obsolete.ECS;
  8. namespace CLre.API.Characters
  9. {
  10. public class Character
  11. {
  12. private bool isCurrent;
  13. private readonly CharacterEngine _characterEngine = new CharacterEngine();
  14. private static readonly FieldInfo _AccountUtility__username =
  15. AccessTools.Field(AccessTools.TypeByName("Game.Utilities.Account.AccountUtility"), "_username");
  16. public string Username
  17. {
  18. get
  19. {
  20. if (isCurrent)
  21. {
  22. return _AccountUtility__username.GetValue(null) as string;
  23. }
  24. return null;
  25. }
  26. }
  27. /// <summary>
  28. /// When enabled, all user flags for the current user are set to one, so they unlock all client functionality
  29. /// </summary>
  30. public bool Superuser
  31. {
  32. get => AccountUtility_GetUserFlags_Patch.superuser;
  33. set => AccountUtility_GetUserFlags_Patch.superuser = value;
  34. }
  35. public static Character Local()
  36. {
  37. Character localChar = new Character();
  38. localChar.isCurrent = true;
  39. return localChar;
  40. }
  41. }
  42. internal class CharacterEngine : GameObsoleteEnginePostBuild
  43. {
  44. public override void Ready()
  45. {
  46. }
  47. public override IEntitiesDB entitiesDB { get; set; }
  48. public override IEntityFactory entityFactory { get; set; }
  49. public bool GetGodModeRequested()
  50. {
  51. if (entitiesDB == null) return false;
  52. // TODO cache this conversion operation
  53. // equivalent to
  54. // return DEPRECATED_SveltoExtensions.GetFirstNodeDeprecatedMethod<Game.GodMode.ClientGodModeRequestNode>()?.godModeRequestComponent.value
  55. Type cgmrd = AccessTools.TypeByName("Game.GodMode.ClientGodModeRequestNode");
  56. Type igmrc = AccessTools.TypeByName("Game.GodMode.IGodModeRequestComponent");
  57. MethodInfo cgmrdFirstNode = AccessTools.Method(typeof(DEPRECATED_SveltoExtensions), "GetFirstNoteDeprecatedMethod")
  58. .MakeGenericMethod(cgmrd);
  59. FieldInfo cgmrdIField = AccessTools.Field(cgmrd, "godModeRequestComponent");
  60. MethodInfo igmrcReqGodMode = AccessTools.PropertyGetter(igmrc, "requestGodMode");
  61. // op start
  62. object firstNode = cgmrdFirstNode.Invoke(null, new []{entitiesDB});
  63. if (firstNode != null)
  64. {
  65. object godModeRequestComponent = cgmrdIField.GetValue(firstNode);
  66. ObsoleteDispatchOnSet<SerialisedBool> requestGodMode = (ObsoleteDispatchOnSet<SerialisedBool>)igmrcReqGodMode.Invoke(godModeRequestComponent, new object[]{});
  67. return requestGodMode.value;
  68. }
  69. return false;
  70. }
  71. public void SetGodModeRequested(bool val)
  72. {
  73. if (entitiesDB == null) return;
  74. // TODO cache this conversion operation
  75. //DEPRECATED_SveltoExtensions.GetFirstNodeDeprecatedMethod<Game.GodMode.ClientGodModeRequestNode>()
  76. Type cgmrd = AccessTools.TypeByName("Game.GodMode.ClientGodModeRequestNode");
  77. Type igmrc = AccessTools.TypeByName("Game.GodMode.IGodModeRequestComponent");
  78. MethodInfo cgmrdFirstNode = AccessTools.Method(typeof(DEPRECATED_SveltoExtensions), "GetFirstNoteDeprecatedMethod")
  79. .MakeGenericMethod(cgmrd);
  80. FieldInfo cgmrdIField = AccessTools.Field(cgmrd, "godModeRequestComponent");
  81. MethodInfo igmrcReqGodMode = AccessTools.PropertyGetter(igmrc, "requestGodMode");
  82. // operation start
  83. object firstNode = cgmrdFirstNode.Invoke(null, new []{entitiesDB});
  84. Utility.Logging.MetaLog($"firstNode is null? {firstNode == null}");
  85. if (firstNode != null)
  86. {
  87. Utility.Logging.MetaLog($"firstNode is type {firstNode.GetType().FullName}");
  88. object godModeRequestComponent = cgmrdIField.GetValue(firstNode);
  89. ObsoleteDispatchOnSet<SerialisedBool> requestGodMode = (ObsoleteDispatchOnSet<SerialisedBool>)igmrcReqGodMode.Invoke(godModeRequestComponent, new object[]{});
  90. requestGodMode.value = val;
  91. Utility.Logging.MetaLog($"SetGodModeRequested completed successfully");
  92. }
  93. }
  94. }
  95. }