Ejemplo n.º 1
0
        private static void CacheAllModInfoAsync()
        {
            var mymod       = ModHelpersMod.Instance;
            var modInfoArgs = new ModInfoListPromiseArguments();

            GetModInfo.RetrieveAllModInfoAsync((modInfo, found) => {
                modInfoArgs.ModInfo = modInfo;
                modInfoArgs.Found   = found;

                Promises.TriggerValidatedPromise(GetModInfo.ModInfoListPromiseValidator, GetModInfo.PromiseValidatorKey, modInfoArgs);
            });

            Promises.AddValidatedPromise <ModInfoListPromiseArguments>(GetModInfo.ModInfoListPromiseValidator, (modInfoArgs2) => {
                if (modInfoArgs2.Found)
                {
                    GetModInfo.RetrieveBadModsAsync((badMods, found) => {
                        if (found)
                        {
                            GetModInfo.RegisterBadMods(modInfoArgs2, badMods);
                        }

                        Promises.TriggerValidatedPromise(GetModInfo.BadModsListPromiseValidator, GetModInfo.PromiseValidatorKey, modInfoArgs2);
                    });
                }

                return(true);
            });
        }
        ////////////////

        public void CheckForNewVersionAsync()
        {
            Promises.AddValidatedPromise <ModInfoListPromiseArguments>(GetModInfo.ModInfoListPromiseValidator, (args) => {
                if (args.Found && args.ModInfo.ContainsKey(this.Mod.Name))
                {
                    this.LatestAvailableVersion = args.ModInfo[this.Mod.Name].Version;
                }
                else
                {
                    if (ModHelpersMod.Instance.Config.DebugModeNetInfo)
                    {
                        LogHelpers.Log("Error retrieving version number of '" + this.Mod.DisplayName + "'");                         //+ "': " + reason );
                    }
                }
                return(false);
            });

            /*Action<Version> onSuccess = delegate ( Version vers ) {
             *      this.LatestAvailableVersion = vers;
             * };
             * Action<string> onFail = delegate ( string reason ) {
             *      if( ModHelpersMod.Instance.Config.DebugModeNetInfo ) {
             *              LogHelpers.Log( "Error retrieving version number of '" + this.Mod.DisplayName + "': " + reason );
             *      }
             * };
             *
             * GetModVersion.GetLatestKnownVersionAsync( this.Mod, onSuccess, onFail );*/
        }
            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();
                });
            }
        public UIModData(UITheme theme, int?idx, Mod mod, bool willDrawOwnHoverElements = true)
        {
            this.InitializeMe(theme, idx, mod, willDrawOwnHoverElements);

            Promises.AddValidatedPromise <ModTagsPromiseArguments>(GetModTags.TagsReceivedPromiseValidator, (args) => {
                ISet <string> modTags = args.ModTags?.GetOrDefault(mod.Name);
                this.ModTags          = modTags ?? this.ModTags;

                return(false);
            });
        }
Ejemplo n.º 5
0
        public override void Show(UIState ui)
        {
            base.Show(ui);

            Timers.SetTimer("ModHelpersUpdatesLoaderPause", 5, () => {
                Promises.AddValidatedPromise <ModInfoListPromiseArguments>(GetModInfo.ModInfoListPromiseValidator, (args) => {
                    this.DisplayModListVersions(ui, args.ModInfo);
                    return(false);
                });
                return(false);
            });
        }
Ejemplo n.º 6
0
        ////////////////

        internal void UpdateMode(bool isEditing)
        {
            if (!isEditing)
            {
                return;
            }

            Promises.AddValidatedPromise <ModInfoListPromiseArguments>(GetModInfo.BadModsListPromiseValidator, (modInfoArgs) => {
                this.ApplyDefaultEditModeTags(modInfoArgs.ModInfo);
                return(false);
            });
        }
Ejemplo n.º 7
0
 private void OnConnectHost()
 {
     //Promises.AddPostWorldLoadOncePromise( () => {
     Promises.AddValidatedPromise(SaveableEntityComponent.LoadAllValidator, () => {
         if (TrainEntity.FindMyTrain(this.player) == -1)
         {
             var ent = TrainEntity.CreateTrainEntity(this.player);
             CustomEntityManager.AddToWorld(ent);
         }
         return(false);
     });
 }
Ejemplo n.º 8
0
        ////////////////

        public override void OnRespawn(Player player)
        {
            Promises.AddValidatedPromise(SaveableEntityComponent.LoadAllValidator, () => {
                Timers.SetTimer("OnARailRespawn", 30, () => {
                    if (this.MyTrainWho != -1)
                    {
                        TrainEntity.WarpPlayerToTrain(player);
                    }
                    return(false);
                });
                return(false);
            });
        }
Ejemplo n.º 9
0
        ////////////////

        public void AddModEntriesAsync(string forModName, IEnumerable <Tuple <string, string> > recomMods)
        {
            foreach (var recomMod in recomMods)
            {
                string recomModName       = recomMod.Item1;
                string recommendedBecause = recomMod.Item2;

                Mod mod = ModLoader.GetMod(recomModName);

                this.AddRawModEntry(mod?.DisplayName, recomModName, recommendedBecause);
            }

            Promises.AddValidatedPromise <ModInfoListPromiseArguments>(GetModInfo.ModInfoListPromiseValidator, (args) => {
                string currModName = ModMenuHelpers.GetModName(MenuContextService.GetPreviousMenuUI(),
                                                               this.MenuContext.MyUI ?? MenuContextService.GetCurrentMenuUI());

                // Validate we're in the same UI
                if (this.MenuContext.MyUI.GetType().Name != "UIModInfo")
                {
                    return(false);
                }
                // Validate we're viewing the mod we started with
                if (forModName != currModName)
                {
                    return(false);
                }

                this.List.RemoveAllChildren();
                this.ModNameList.Clear();

                foreach (var recomMod in recomMods)
                {
                    string recomModName       = recomMod.Item1;
                    string recommendedBecause = recomMod.Item2;

                    if (args.ModInfo.ContainsKey(recomModName))
                    {
                        this.AddModEntry(args.ModInfo[recomModName].DisplayName, recomModName, recommendedBecause);
                    }
                    else
                    {
                        this.AddRawModEntry(null, recomModName, recommendedBecause);
                    }
                }

                return(false);
            });

            this.EmptyText.Remove();
            this.Recalculate();
        }
Ejemplo n.º 10
0
        ////////////////

        public void FilterModsAsync(IList <string> modNames, Action <bool, IList <string>, int, int> callback)
        {
            Promises.AddValidatedPromise <ModTagsPromiseArguments>(GetModTags.TagsReceivedPromiseValidator, (args) => {
                if (!args.Found)
                {
                    this.InfoDisplay?.SetText("Could not acquire mod data.");
                    callback(false, new List <string>(), 0, 0);
                    return(false);
                }

                this.FilterMods_Promised(modNames, callback, args.ModTags);
                return(false);
            });
        }
Ejemplo n.º 11
0
        public override void Show(UIState ui)
        {
            base.Show(ui);

            this.BeginModBrowserPopulateCheck(ui);
            this.RecalculateMenuObjects();
            this.EnableTagButtons();

            this.InfoDisplay.SetDefaultText("Click tags to filter the list. Right-click tags to filter without them.");

            UIElement elem;

            if (ReflectionHelpers.Get <UIElement>(ui, "uIElement", out elem))
            {
                elem.Left.Pixels += UITagButton.ColumnWidth;
                elem.Recalculate();
            }

            Promises.AddValidatedPromise <ModTagsPromiseArguments>(GetModTags.TagsReceivedPromiseValidator, (args) => {
                Timers.SetTimer("ModBrowserDefaultTagStates", 15, () => {
                    if (this.MyUI != ui)
                    {
                        return(false);
                    }

                    bool isLoading;
                    if (!ReflectionHelpers.Get(this.MyUI, "loading", out isLoading))
                    {
                        LogHelpers.Warn("ModBrowserTagsMenuContext - No 'loading'.");
                        return(false);
                    }

                    if (isLoading)
                    {
                        return(true);
                    }
                    else
                    {
                        UITagButton button = this.TagButtons["Misleading Info"];
                        button.SetTagState(-1);
                        return(false);
                    }
                });
                return(true);
            });
        }
Ejemplo n.º 12
0
        ////////////////

        protected override bool ReceiveRequestWithServer(int from_who)
        {
            Player player = Main.player[from_who];

            Promises.AddValidatedPromise(SaveableEntityComponent.LoadAllValidator, () => {
                if (TrainEntity.FindMyTrain(player) != -1)
                {
                    throw new HamstarException("Cannot spawn duplicate train for player " + player.name);
                }

                var ent = TrainEntity.CreateTrainEntity(player);
                CustomEntityManager.AddToWorld(ent);

                return(false);
            });

            return(true);
        }
        internal CustomEntityManager()
        {
            this.InitializeUpdate();
            this.InitializeEntityTypes();
            this.InitializeComponentTypes();
            this.InitializeDrawingLayer();

            // Reset any data from previous games
            Promises.AddPostWorldUnloadEachPromise(() => {
                lock (CustomEntityManager.MyLock) {
                    this.WorldEntitiesByIndexes.Clear();
                    this.WorldEntitiesByComponentType.Clear();
                }
            });

            // Bind 'data dump' hotkey
            DataDumper.SetDumpSource("CustomEntityList", () => {
                lock (CustomEntityManager.MyLock) {
                    return(string.Join("\n  ", this.WorldEntitiesByIndexes.OrderBy(kv => kv.Key)
                                       .SafeSelect(kv => kv.Key + ": " + kv.Value?.ToString() ?? "null")));
                }
            });

            // Refresh entity owners on player connect and sync entities to player
            if (Main.netMode == 2)
            {
                Promises.AddValidatedPromise <PlayerLogicPromiseArguments>(PlayerLogic.ServerConnectValidator, (args) => {
                    if (this.WorldEntitiesByIndexes.Count == 0)
                    {
                        return(true);
                    }

                    foreach (var ent in this.WorldEntitiesByIndexes.Values)
                    {
                        ent.RefreshOwnerWho();
                    }

                    PacketProtocolSendToClient.QuickSend <CustomEntityAllProtocol>(args.Who, -1);

                    return(true);
                });
            }
        }
Ejemplo n.º 14
0
        public override void SetDefaults()
        {
            this.DisplayName.SetDefault("Train");
            this.Description.SetDefault("Your home away from home.");

            Main.buffNoTimeDisplay[this.Type] = true;
            Main.buffNoSave[this.Type]        = true;

            if (!OnARailMod.Instance.HasBuffPromise)
            {
                OnARailMod.Instance.HasBuffPromise = true;

                Promises.AddValidatedPromise <PlayerPromiseArguments>(OnARailPlayer.PlayerFuncsValidator, (args) => {
                    var mybuff = OnARailMod.Instance.GetBuff <TrainMountBuff>();
                    mybuff.RunUpdateForPlayer(Main.player[args.Who]);
                    return(true);
                });
            }
        }
Ejemplo n.º 15
0
        public static void IsListModProperlyPresented(string modName, Action <bool> callback)
        {
            Promises.AddValidatedPromise <ModInfoListPromiseArguments>(GetModInfo.ModInfoListPromiseValidator, (args) => {
                if (args.Found && args.ModInfo.ContainsKey(modName))
                {
                    BasicModInfoEntry modInfo = args.ModInfo[modName];

                    bool isProper = ModIdentityHelpers.IsProperlyPresented(modInfo);

                    callback(isProper);
                }
                else
                {
                    if (ModHelpersMod.Instance.Config.DebugModeNetInfo)
                    {
                        LogHelpers.Log("Error retrieving mod data for '" + modName + "'");                           //+ "': " + reason );
                    }
                }
                return(false);
            });
        }
Ejemplo n.º 16
0
        public override void SetDefaults()
        {
            int total_frames = 4;

            var player_y_offsets = new int[total_frames];

            for (int i = 0; i < player_y_offsets.Length; i++)
            {
                player_y_offsets[i] = 32;
            }

            this.mountData.Minecart            = true;
            this.mountData.MinecartDirectional = true;
            this.mountData.MinecartDust        = new Action <Vector2>(DelegateMethods.Minecart.Sparks);
            this.mountData.spawnDust           = 213;
            this.mountData.buff = this.mod.BuffType("TrainMountBuff");
            //this.mountData.extraBuff = 185;
            this.mountData.flightTimeMax   = 0;
            this.mountData.fallDamage      = 1f;
            this.mountData.runSpeed        = 20f;       //10f;
            this.mountData.dashSpeed       = 10f;
            this.mountData.acceleration    = 0.05f;     //0.03f;
            this.mountData.jumpHeight      = 2;         //12;
            this.mountData.jumpSpeed       = 5.15f;
            this.mountData.blockExtraJumps = true;

            this.mountData.totalFrames      = total_frames;
            this.mountData.heightBoost      = 30;
            this.mountData.playerYOffsets   = player_y_offsets;
            this.mountData.xOffset          = 0;   //8;
            this.mountData.yOffset          = 2;
            this.mountData.bodyFrame        = 3;
            this.mountData.playerHeadOffset = 14;

            this.mountData.standingFrameCount = 1;
            this.mountData.standingFrameDelay = 12;
            this.mountData.standingFrameStart = 0;
            this.mountData.runningFrameCount  = 4;
            this.mountData.runningFrameDelay  = 12;
            this.mountData.runningFrameStart  = 0;
            this.mountData.flyingFrameCount   = 0;
            this.mountData.flyingFrameDelay   = 0;
            this.mountData.flyingFrameStart   = 0;
            this.mountData.inAirFrameCount    = 0;
            this.mountData.inAirFrameDelay    = 0;
            this.mountData.inAirFrameStart    = 0;
            this.mountData.idleFrameCount     = 4;
            this.mountData.idleFrameDelay     = 12;
            this.mountData.idleFrameStart     = 0;
            this.mountData.idleFrameLoop      = false;

            if (Main.netMode != 2)
            {
                this.mountData.textureWidth  = this.mountData.backTexture.Width;
                this.mountData.textureHeight = this.mountData.backTexture.Height;
            }

            if (!OnARailMod.Instance.HasMountPromise)
            {
                OnARailMod.Instance.HasMountPromise = true;

                Promises.AddValidatedPromise <PlayerPromiseArguments>(OnARailPlayer.PlayerFuncsValidator, (args) => {
                    var mymount = OnARailMod.Instance.GetMount <TrainMount>();
                    mymount.RunUpdateForPlayer(Main.player[args.Who]);
                    return(true);
                });
            }
        }
Ejemplo n.º 17
0
        ////////////////

        private void SetCurrentMod(UIState ui, string modName)
        {
            this.CurrentModName = modName;

            Promises.AddValidatedPromise <ModTagsPromiseArguments>(GetModTags.TagsReceivedPromiseValidator, (args) => {
                if (!args.Found)
                {
                    LogHelpers.Warn();
                    return(false);
                }

                this.AllModTagsSnapshot = args.ModTags;

                ISet <string> netModTags = args.Found && args.ModTags.ContainsKey(modName) ?
                                           args.ModTags[modName] :
                                           new HashSet <string>();
                bool hasNetTags = netModTags.Count > 0;

//LogHelpers.Log( "SetCurrentMod modname: " + modName + ", modTags: " + string.Join(",", netModTags ) );
                if (hasNetTags)
                {
                    this.InfoDisplay.SetDefaultText("Do these tags look incorrect? If so, modify them.");
                    this.FinishButton.SetModeReadOnly();
                    this.ResetButton.Disable();
                }
                else
                {
                    this.InfoDisplay.SetDefaultText("No tags set for this mod. Why not add some?");
                    this.FinishButton.SetModeSubmit();
                }

                foreach (var kv in this.TagButtons)
                {
                    string tagName     = kv.Key;
                    UITagButton button = kv.Value;
                    bool hasTag        = netModTags.Contains(tagName);

                    if (!hasNetTags)
                    {
                        button.Enable();
                    }

                    if (tagName == "Low Effort")
                    {
                        if (hasTag)
                        {
                            button.SetTagState(1);
                        }
                        else
                        {
                            string desc = this.GetModDataFromActiveMod(modName, "description");
                            if (string.IsNullOrEmpty(desc))
                            {
                                string _ = "";
                                desc     = this.GetModDescriptionFromUI(modName, ref _);
                            }

                            if (desc.Contains("Modify this file with a description of your mod."))
                            {
                                button.SetTagState(1);
                            }
                        }
                    }
                    else
                    {
                        button.SetTagState(hasTag ? 1 : 0);
                    }
                }

                return(false);
            });
        }
        public static CustomEntity AddToWorld(int who, CustomEntity ent, bool skipSync = false)
        {
            //if( ent == null ) { throw new HamstarException( "!ModHelpers.CustomEntityManager.AddToWorld - Null ent not allowed." ); }
            //if( !ent.IsInitialized ) { throw new HamstarException( "!ModHelpers.CustomEntityManager.AddToWorld - Initialized ents only." ); }
            if (ent == null)
            {
                throw new HamstarException("Null ent not allowed.");
            }
            if (!ent.IsInitialized)
            {
                throw new HamstarException("Initialized ents only.");
            }

            CustomEntityManager mngr    = ModHelpersMod.Instance.CustomEntMngr;
            CustomEntity        realEnt = ent;

            if (mngr.WorldEntitiesByIndexes.ContainsKey(who))
            {
                //throw new HamstarException( "!ModHelpers.CustomEntityManager.AddToWorld - "
                //	+ "Attempting to add "+ent.ToString()+" to slot "+who+" occupied by "+mngr.WorldEntitiesByIndexes[who].ToString() );
                throw new HamstarException("Attempting to add " + ent.ToString() + " to slot " + who + " occupied by "
                                           + mngr.WorldEntitiesByIndexes[who].ToString());
            }

            if (ent is SerializableCustomEntity)
            {
                realEnt = ((SerializableCustomEntity)ent).Convert();
            }

            Type compType;
            Type baseType = typeof(CustomEntityComponent);

            // Map entity to each of its components
            foreach (CustomEntityComponent component in realEnt.InternalComponents)
            {
                compType = component.GetType();
                lock (CustomEntityManager.MyLock) {
                    do
                    {
                        if (!mngr.WorldEntitiesByComponentType.ContainsKey(compType))
                        {
                            mngr.WorldEntitiesByComponentType[compType] = new HashSet <int>();
                        }

                        mngr.WorldEntitiesByComponentType[compType].Add(who);

                        compType = compType.BaseType;
                    } while(compType != baseType);
                }
            }

            realEnt.Core.whoAmI = who;
            mngr.WorldEntitiesByIndexes[who] = realEnt;

            realEnt.InternalOnAddToWorld();

            // Sync also
            if (!skipSync)
            {
                if (Main.netMode == 1)
                {
                    if (ent.SyncFromClient)
                    {
                        Promises.AddValidatedPromise(SaveableEntityComponent.LoadAllValidator, () => {
                            ent.SyncToAll();
                            return(false);
                        });
                    }
                }
                else if (Main.netMode == 2)
                {
                    if (ent.SyncFromServer)
                    {
                        Promises.AddValidatedPromise(SaveableEntityComponent.LoadAllValidator, () => {
                            ent.SyncToAll();
                            return(false);
                        });
                    }
                }
            }

            if (ModHelpersMod.Instance.Config.DebugModeCustomEntityInfo)
            {
                LogHelpers.Alert("Set " + realEnt.ToString());
            }

            return(realEnt);
        }