/// <summary>
 /// Registers this instance of the PLib core patches.
 /// </summary>
 /// <param name="instance">The registry instance to use (since PRegistry.Instance
 /// is not yet fully initialized).</param>
 internal void Register(IPLibRegistry instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException(nameof(instance));
     }
     instance.AddCandidateVersion(this);
 }
Beispiel #2
0
        /// <summary>
        /// Initializes the patch bootstrapper, creating a PRegistry if not yet present.
        /// </summary>
        private static void Init()
        {
            const string INTENDED_NAME = "PRegistryComponent";
            var          obj           = Global.Instance?.gameObject;

            if (obj != null)
            {
                var plr = obj.GetComponent(INTENDED_NAME);
                if (plr == null)
                {
                    var localReg = obj.AddComponent <PRegistryComponent>();
                    // If PLib is ILMerged more than once, PRegistry gets added with a weird
                    // type name including a GUID which does not match GetComponent.Name!
                    string typeName = localReg.GetType().Name;
                    if (typeName != INTENDED_NAME)
                    {
                        LogPatchWarning(INTENDED_NAME + " has the type name " + typeName +
                                        "; this may be the result of ILMerging PLib more than once!");
                    }
#if DEBUG
                    LogPatchDebug("Creating PLib Registry from " + System.Reflection.Assembly.
                                  GetExecutingAssembly()?.FullName ?? "?");
#endif
                    // Patch in the bootstrap method
                    localReg.ApplyBootstrapper();
                    instance = localReg;
                }
                else
                {
                    instance = new PRemoteRegistry(plr);
                }
            }
            else
            {
#if DEBUG
                LogPatchWarning("Attempted to initialize PLib Registry before Global created!");
#endif
                instance = null;
            }
            if (instance != null)
            {
                new PLibCorePatches().Register(instance);
            }
        }