private static void LoadAll()
            {
                var mymod = ModHelpersMod.Instance;

                if (mymod.Config.DebugModeResetCustomEntities)
                {
                    return;
                }

                try {
                    if (!SaveableEntityComponent.LoadAll(true))
                    {
                        if (mymod.Config.DebugModeNetInfo)
                        {
                            LogHelpers.Log("!ModHelpers.SaveableEntityComponent.StaticInitialize.LoadAll - Load (json) failed.");
                        }
                    }
                    if (!SaveableEntityComponent.LoadAll(false))
                    {
                        if (mymod.Config.DebugModeNetInfo)
                        {
                            LogHelpers.Log("!ModHelpers.SaveableEntityComponent.StaticInitialize.LoadAll - Load (no json) failed.");
                        }
                    }
                } catch (Exception e) {
                    LogHelpers.Log("!ModHelpers.SaveableEntityComponent.StaticInitialize.LoadAll - " + e.ToString());
                }
            }
            protected override void StaticInitialize()
            {
                // Load all entities upon world load (single, server)
                if (Main.netMode != 1)
                {
                    Promises.AddValidatedPromise <PromiseArguments>(ModHelpersWorld.LoadValidator, (_) => {
                        MyStaticInitializer.LoadAll();
                        SaveableEntityComponent.PostLoadAll();
                        return(true);
                    });
                }

                // Save all entities upon world save (single, server)
                if (Main.netMode != 1)
                {
                    Promises.AddValidatedPromise <PromiseArguments>(ModHelpersWorld.SaveValidator, (_) => {
                        MyStaticInitializer.SaveAll();
                        return(true);
                    });
                }

                // Unload entities after world closes
                Promises.AddPostWorldUnloadEachPromise(() => {
                    SaveableEntityComponent.PostUnloadAll();
                });
            }
        private static void SaveAll(bool isJson)
        {
            var    mymod    = ModHelpersMod.Instance;
            string fileName = SaveableEntityComponent.GetFileNameBase();

            IList <SerializableCustomEntity> wrappedEnts = new List <SerializableCustomEntity>();

            foreach (var ent in CustomEntityManager.GetEntitiesByComponent <SaveableEntityComponent>())
            {
                if (ent.GetComponentByType <SaveableEntityComponent>().AsJson != isJson)
                {
                    continue;
                }

                wrappedEnts.Add(new SerializableCustomEntity(ent));
            }

            if (wrappedEnts.Count > 0)
            {
                if (isJson)
                {
                    DataFileHelpers.SaveAsJson(mymod, fileName, CustomEntityConverter.SerializerSettings, wrappedEnts);
                }
                else
                {
                    DataFileHelpers.SaveAsBinary(mymod, fileName + ".dat", false, CustomEntityConverter.SerializerSettings, wrappedEnts);
                }
            }
        }
        private static bool LoadAll(bool isJson)
        {
            var    mymod    = ModHelpersMod.Instance;
            string fileName = SaveableEntityComponent.GetFileNameBase();
            bool   success  = false;
            IList <SerializableCustomEntity> wrappedEnts = null;

            try {
                if (isJson)
                {
                    wrappedEnts = DataFileHelpers.LoadJson <List <SerializableCustomEntity> >(mymod, fileName, CustomEntityConverter.SerializerSettings, out success);
                }
                else
                {
                    wrappedEnts = DataFileHelpers.LoadBinary <List <SerializableCustomEntity> >(mymod, fileName + ".dat", false, CustomEntityConverter.SerializerSettings);
                    success     = wrappedEnts != null;
                }

                if (success)
                {
                    foreach (SerializableCustomEntity ent in wrappedEnts)
                    {
                        if (ent == null)
                        {
                            continue;
                        }
                        CustomEntity realEnt = ent.Convert();
                        CustomEntityManager.AddToWorld(realEnt);
                    }
                }
            } catch (Exception e) {
                LogHelpers.Log("!ModHelpers.SaveableEntityComponent.LoadAll - " + e.ToString());
            }

            return(success);
        }
 private static void SaveAll()
 {
     SaveableEntityComponent.SaveAll(true);
     SaveableEntityComponent.SaveAll(false);
 }