コード例 #1
0
        // Token: 0x0600238B RID: 9099 RVA: 0x000A750C File Offset: 0x000A570C
        public void OnClick()
        {
            if (!this.canVote)
            {
                return;
            }
            NetworkUser networkUser = this.FindNetworkUser();

            Debug.Log(networkUser);
            if (networkUser)
            {
                PreGameRuleVoteController preGameRuleVoteController = PreGameRuleVoteController.FindForUser(networkUser);
                if (preGameRuleVoteController)
                {
                    int choiceValue = this.currentChoiceDef.localIndex;
                    if (preGameRuleVoteController.IsChoiceVoted(this.currentChoiceDef))
                    {
                        choiceValue = -1;
                    }
                    preGameRuleVoteController.SetVote(this.currentChoiceDef.ruleDef.globalIndex, choiceValue);
                    Debug.LogFormat("voteController.SetVote({0}, {1})", new object[]
                    {
                        this.currentChoiceDef.ruleDef.globalIndex,
                        this.currentChoiceDef.localIndex
                    });
                    return;
                }
                Debug.Log("voteController=null");
            }
        }
コード例 #2
0
        // Token: 0x06002388 RID: 9096 RVA: 0x000A7378 File Offset: 0x000A5578
        public void UpdateFromVotes()
        {
            int  num = PreGameRuleVoteController.votesForEachChoice[this.currentChoiceDef.globalIndex];
            bool isInSinglePlayer = RoR2Application.isInSinglePlayer;

            if (num > 0 && !isInSinglePlayer)
            {
                this.voteCounter.enabled = true;
                this.voteCounter.text    = num.ToString();
            }
            else
            {
                this.voteCounter.enabled = false;
            }
            bool        enabled     = false;
            NetworkUser networkUser = this.FindNetworkUser();

            if (networkUser)
            {
                PreGameRuleVoteController preGameRuleVoteController = PreGameRuleVoteController.FindForUser(networkUser);
                if (preGameRuleVoteController)
                {
                    enabled = preGameRuleVoteController.IsChoiceVoted(this.currentChoiceDef);
                }
            }
            this.selectionDisplayPanel.enabled = enabled;
        }
コード例 #3
0
        private RuleChoiceDef PreGameRuleVoteController_GetDefaultChoice(On.RoR2.PreGameRuleVoteController.orig_GetDefaultChoice orig, PreGameRuleVoteController self, RuleDef ruleDef)
        {
            int choice = PreGameController.instance.readOnlyRuleBook.GetRuleChoiceIndex(ruleDef);

            if (!ruleDef.category.isHidden)
            {
                string catagory = ruleDef.category.displayToken;
                string name     = ruleDef.globalName;
                choice = configfile.Wrap(catagory, name, null, choice).Value;
            }

            return(ruleDef.choices[choice]);
        }
コード例 #4
0
        private void PreGameRuleVoteController_SetVote(On.RoR2.PreGameRuleVoteController.orig_SetVote orig, PreGameRuleVoteController self, int ruleIndex, int choiceValue)
        {
            var ruledef = RuleCatalog.GetRuleDef(ruleIndex);

            if (!ruledef.category.isHidden)
            {
                if (choiceValue >= 0)
                {
                    string catagorie = ruledef.category.displayToken;
                    string name      = ruledef.globalName;
                    configfile.Wrap(catagorie, name, null, choiceValue).Value = choiceValue;
                }
            }

            orig(self, ruleIndex, choiceValue);
        }
コード例 #5
0
        static void PreGameRuleVoteControllerDeserialize(On.RoR2.PreGameRuleVoteController.orig_ReadVotes orig, PreGameRuleVoteController self, NetworkReader reader)
        {
            Array    votes          = self.GetType().GetField("votes", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(self) as Array;
            RuleMask ruleMaskBuffer = self.GetFieldValue <RuleMask>("ruleMaskBuffer");

            reader.ReadRuleMask(ruleMaskBuffer);
            bool flag = !self.networkUserNetworkIdentity || !self.networkUserNetworkIdentity.isLocalPlayer;

            for (int i = 0; i < RuleCatalog.ruleCount - RegisteredVoteSelections.Count; i++)
            {
                object vote;
                if (ruleMaskBuffer[i])
                {
                    vote = votes.GetValue(i).GetType().InvokeMethod <object>("Deserialize", reader);
                }
                else
                {
                    vote = default(object);
                }
                if (flag)
                {
                    votes.SetValue(vote, i);
                }
            }

            if (TargetedRuleMask != null)
            {
                if (reader.Position < reader.Length)
                {
                    byte[] bytes      = (byte[])TargetedRuleMask.GetType().BaseType.GetField("bytes", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(TargetedRuleMask);
                    int    difference = bytes.Length - ((RuleCatalog.ruleCount - RegisteredVoteSelections.Count) + 7 >> 3);
                    for (int i = bytes.Length - difference; i < bytes.Length; i++)
                    {
                        bytes[i] = reader.ReadByte();
                    }

                    for (int i = RuleCatalog.ruleCount - RegisteredVoteSelections.Count; i < RuleCatalog.ruleCount; i++)
                    {
                        object vote;
                        if (ruleMaskBuffer[i])
                        {
                            vote = votes.GetValue(i).GetType().InvokeMethod <object>("Deserialize", reader);
                        }
                        else
                        {
                            vote = default(object);
                        }
                        if (flag)
                        {
                            votes.SetValue(vote, i);
                        }
                    }
                }
                TargetedRuleMask = null;
            }

            self.GetType().GetField("shouldUpdateGameVotes", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, ((bool)self.GetType().GetField("shouldUpdateGameVotes", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null) || flag));
            if (NetworkServer.active)
            {
                self.SetDirtyBit(2u);
            }
        }
コード例 #6
0
        static void PreGameRuleVoteControllerSerialize(On.RoR2.PreGameRuleVoteController.orig_WriteVotes orig, PreGameRuleVoteController self, NetworkWriter writer)
        {
            Array    votes          = self.GetType().GetField("votes", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(self) as Array;
            RuleMask ruleMaskBuffer = self.GetFieldValue <RuleMask>("ruleMaskBuffer");

            for (int i = 0; i < RuleCatalog.ruleCount; i++)
            {
                ruleMaskBuffer[i] = votes.GetValue(i).GetPropertyValue <bool>("hasVoted");
            }
            writer.Write(ruleMaskBuffer);
            for (int i = 0; i < RuleCatalog.ruleCount - RegisteredVoteSelections.Count; i++)
            {
                if (votes.GetValue(i).GetPropertyValue <bool>("hasVoted"))
                {
                    votes.GetValue(i).GetType().InvokeMethod("Serialize", writer, votes.GetValue(i));
                }
            }

            for (int i = 0; i < RuleMaskExtraBytes.Count; i++)
            {
                writer.Write(RuleMaskExtraBytes[i]);
            }
            for (int i = RuleCatalog.ruleCount - RegisteredVoteSelections.Count; i < RuleCatalog.ruleCount; i++)
            {
                if (votes.GetValue(i).GetPropertyValue <bool>("hasVoted"))
                {
                    votes.GetValue(i).GetType().InvokeMethod("Serialize", writer, votes.GetValue(i));
                }
            }
            RuleMaskExtraBytes.Clear();
        }