internal PRemoteComponent(object wrapped) { this.wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped)); if (!PPatchTools.TryGetPropertyValue(wrapped, nameof(Version), out Version version)) { throw new ArgumentException("Remote component missing Version property"); } this.version = version; // Initialize var type = wrapped.GetType(); doInitialize = type.CreateDelegate <InitializeDelegate>(nameof(PForwardedComponent. Initialize), wrapped, typeof(Harmony)); if (doInitialize == null) { throw new ArgumentException("Remote component missing Initialize"); } // Bootstrap doBootstrap = type.CreateDelegate <InitializeDelegate>(nameof(PForwardedComponent. Bootstrap), wrapped, typeof(Harmony)); doPostInitialize = type.CreateDelegate <InitializeDelegate>(nameof( PForwardedComponent.PostInitialize), wrapped, typeof(Harmony)); getData = type.CreateGetDelegate <object>(nameof(InstanceData), wrapped); setData = type.CreateSetDelegate <object>(nameof(InstanceData), wrapped); process = type.CreateDelegate <ProcessDelegate>(nameof(PForwardedComponent. Process), wrapped, typeof(uint), typeof(object)); }
/// <summary> /// Creates a remote registry wrapping the target object. /// </summary> /// <param name="instance">The PRegistryComponent instance to wrap.</param> internal PRemoteRegistry(object instance) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } remoteComponents = new Dictionary <string, PForwardedComponent>(32); if (!PPatchTools.TryGetPropertyValue(instance, nameof(ModData), out IDictionary <string, object> modData)) { throw new ArgumentException("Remote instance missing ModData"); } ModData = modData; var type = instance.GetType(); addCandidateVersion = type.CreateDelegate <Action <object> >(nameof( PRegistryComponent.DoAddCandidateVersion), instance, typeof(object)); getAllComponents = type.CreateDelegate <GetAllComponentsDelegate>(nameof( PRegistryComponent.DoGetAllComponents), instance, typeof(string)); getLatestVersion = type.CreateDelegate <GetObjectDelegate>(nameof( PRegistryComponent.DoGetLatestVersion), instance, typeof(string)); if (addCandidateVersion == null || getLatestVersion == null || getAllComponents == null) { throw new ArgumentException("Remote instance missing candidate versions"); } getSharedData = type.CreateDelegate <GetObjectDelegate>(nameof(IPLibRegistry. GetSharedData), instance, typeof(string)); setSharedData = type.CreateDelegate <SetObjectDelegate>(nameof(IPLibRegistry. SetSharedData), instance, typeof(string), typeof(object)); if (getSharedData == null || setSharedData == null) { throw new ArgumentException("Remote instance missing shared data"); } }
private static IEnumerable <CodeInstruction> LoadPreviewImage_Transpile( IEnumerable <CodeInstruction> body) { var target = typeof(Debug).GetMethodSafe(nameof(Debug.LogFormat), true, typeof(string), typeof(object[])); return((target == null) ? body : PPatchTools.ReplaceMethodCall(body, target)); }
/// <summary> /// Retrieves the current game version from the Klei code. /// </summary> /// <returns>The change list version of the game, or 0 if it cannot be determined.</returns> private static uint GetGameVersion() { /* * KleiVersion.ChangeList is a const which is substituted at compile time; if * accessed directly, PLib would have a version "baked in" and would never * update depending on the game version in use. */ var field = PPatchTools.GetFieldSafe(typeof(KleiVersion), nameof(KleiVersion. ChangeList), true); uint ver = 0U; if (field != null && field.GetValue(null) is uint newVer) { ver = newVer; } return(ver); }
public override void Initialize(Harmony plibInstance) { UI.TextMeshProPatcher.Patch(); var ugc = PPatchTools.GetTypeSafe("SteamUGCService", "Assembly-CSharp"); if (ugc != null) { try { plibInstance.PatchTranspile(ugc, "LoadPreviewImage", PatchMethod(nameof( LoadPreviewImage_Transpile))); } catch (Exception e) { #if DEBUG PUtil.LogExcWarn(e); #endif } } plibInstance.Patch(typeof(Localization), nameof(Localization.Initialize), postfix: PatchMethod(nameof(Initialize_Postfix))); }