Add account superuser and game framework events

This commit is contained in:
NGnius (Graham) 2020-12-24 15:51:17 -05:00
parent 42029cf0fd
commit 4a51207dc6
6 changed files with 250 additions and 4 deletions

View file

@ -30,13 +30,42 @@ namespace CLre.API.App
remove => FrontEndGuiEngine_SetMainMenuEnabled_Patch.postMenuEnabled -= value; remove => FrontEndGuiEngine_SetMainMenuEnabled_Patch.postMenuEnabled -= value;
} }
public static event EventHandler<MenuReady> MenuReady
{
add => MenuReadyEngine.menuEngineReady += value;
remove => MenuReadyEngine.menuEngineReady -= value;
}
public static event EventHandler<GameReady> GameReady
{
add => GameReadyEngine.gameEngineReady += value;
remove => GameReadyEngine.gameEngineReady -= value;
}
public static event EventHandler<GameReady> GameFrameworkReady
{
add => GameFrameworkEngine.gameFrameworkReady += value;
remove => GameFrameworkEngine.gameFrameworkReady += value;
}
public static event EventHandler<GameExit> GameFrameworkExit
{
add => GameFrameworkEngine.gameFrameworkExit += value;
remove => GameFrameworkEngine.gameFrameworkExit += value;
}
public static string Version public static string Version
{ {
get => Game.Utilities.VersionReader.GetVersion(); get => Game.Utilities.VersionReader.GetVersion();
} }
}
public struct SetupEventArgs {} static Client()
{
new MenuReadyEngine();
new GameReadyEngine();
new GameFrameworkEngine();
}
}
[HarmonyPatch(typeof(FrontEnd.MainFrontEnd), "SetupContainer")] [HarmonyPatch(typeof(FrontEnd.MainFrontEnd), "SetupContainer")]
class FrontEnd_SetupContainer_Patch class FrontEnd_SetupContainer_Patch

View file

@ -0,0 +1,62 @@
using System;
using CLre.API.Engines;
using Svelto.Context;
using Svelto.ECS;
namespace CLre.API.App
{
class GameReadyEngine : GameObsoleteEnginePostBuild, IWaitForFrameworkInitialization
{
internal static event EventHandler<GameReady> gameEngineReady;
public override void Ready()
{
if (gameEngineReady != null) gameEngineReady(this, new GameReady { });
}
public override IEntitiesDB entitiesDB { get; set; }
public override IEntityFactory entityFactory { get; set; }
public void OnFrameworkInitialized()
{
// TODO framework init event
}
}
class GameFrameworkEngine : GameObsoleteEnginePostBuild, IWaitForFrameworkInitialization, IWaitForFrameworkDestruction
{
internal static event EventHandler<GameReady> gameFrameworkReady;
internal static event EventHandler<GameExit> gameFrameworkExit;
public override void Ready()
{
}
public override IEntitiesDB entitiesDB { get; set; }
public override IEntityFactory entityFactory { get; set; }
public void OnFrameworkInitialized()
{
if (gameFrameworkReady != null) gameFrameworkReady(this, new GameReady { });
}
public void OnFrameworkDestroyed()
{
if (gameFrameworkExit != null) gameFrameworkExit(this, new GameExit { });
}
}
class MenuReadyEngine : FrontEndObsoleteEnginePostBuild
{
internal static event EventHandler<MenuReady> menuEngineReady;
public override void Ready()
{
if (menuEngineReady != null) menuEngineReady(this, new MenuReady { });
}
public override IEntitiesDB entitiesDB { get; set; }
public override IEntityFactory entityFactory { get; set; }
}
}

View file

@ -0,0 +1,11 @@
namespace CLre.API.App
{
public struct SetupEventArgs {}
public struct GameReady{}
public struct GameExit{}
public struct MenuReady{}
}

View file

@ -0,0 +1,28 @@
using System.Reflection;
using HarmonyLib;
using User.Server;
namespace CLre.API.Characters
{
[HarmonyPatch]
class AccountUtility_GetUserFlags_Patch
{
internal static bool superuser = false;
private static UserFlags superFlags = UserFlags.userlogged | UserFlags.BucketB | UserFlags.BucketA |
UserFlags.NoDrop | UserFlags.GiveInv | UserFlags.Dev | UserFlags.None;
[HarmonyPrefix]
public static bool BeforeMethodCall(ref UserFlags __result)
{
if (superuser) __result = superFlags;
return !superuser;
}
[HarmonyTargetMethod]
public static MethodBase Target()
{
return AccessTools.Method("Game.Utilities.Account.AccountUtility:GetUserFlags");
}
}
}

View file

@ -0,0 +1,107 @@
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;
}
}
/// <summary>
/// When enabled, all user flags for the current user are set to one, so they unlock all client functionality
/// </summary>
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<Game.GodMode.ClientGodModeRequestNode>()?.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<SerialisedBool> requestGodMode = (ObsoleteDispatchOnSet<SerialisedBool>)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<Game.GodMode.ClientGodModeRequestNode>()
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<SerialisedBool> requestGodMode = (ObsoleteDispatchOnSet<SerialisedBool>)igmrcReqGodMode.Invoke(godModeRequestComponent, new object[]{});
requestGodMode.value = val;
Utility.Logging.MetaLog($"SetGodModeRequested completed successfully");
}
}
}
}

View file

@ -3,13 +3,14 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using CLre.API.Characters;
using HarmonyLib; using HarmonyLib;
using Svelto.ECS; using Svelto.ECS;
using UnityEngine; using UnityEngine;
namespace CLre namespace CLre
{ {
public class CLre : IllusionPlugin.IEnhancedPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin' public class CLre : IllusionPlugin.IEnhancedPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin
{ {
public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
@ -55,6 +56,14 @@ namespace CLre
? EasyAntiCheat.Client.Hydra.Runtime.Integrity.ViolationMessage ? EasyAntiCheat.Client.Hydra.Runtime.Integrity.ViolationMessage
: "")); : ""));
}; };
API.App.Client.MenuReady += (_, __) => { API.Utility.Logging.MetaLog("Menu engine ready event fired!"); };
API.App.Client.GameReady += (_, __) => { API.Utility.Logging.MetaLog("Game engine ready event fired!"); };
API.App.Client.GameFrameworkReady += (_, __) => { API.Utility.Logging.MetaLog("Game framework ready event fired!"); };
API.App.Client.GameFrameworkExit += (_, __) => { API.Utility.Logging.MetaLog("Game framework exit event fired!"); };
Character c = Character.Local();
c.Superuser = true;
#endif #endif
} }