反系统时间作弊无法完全正常工作

时间:2018-08-10 00:30:20

标签: c# unity3d systemtime

发生了什么事: 它在大多数情况下都有效,除了使用脱机硬币计数后的一段时间总是为0之后。我正在尝试使其无法让玩家改变系统时间来尝试更快地获得更多钱。我也没有尝试通过连接服务器来进行时间检查。有人看到出什么问题了吗?

如果语句处于唤醒状态:

if (PlayerPrefs.GetInt("offlineCheck").Equals(1))
        {
            ButtonCanvas.gameObject.SetActive(false);
            OfflineCanvas.gameObject.SetActive(true);
            PlayerPrefs.SetInt("offlineCheck", 0);
            // year not the same
            if (!PlayerPrefs.GetInt("year").Equals(System.DateTime.Now.Year))
            {
                // Add 24 Hour Coins
                if (PlayerPrefs.GetInt("year") < System.DateTime.Now.Year)
                {
                    offlineCoinCount = PlayerPrefs.GetInt("OfflineCoinsVal") * (24 * 60);
                } else {
                    offlineCoinCount = 0;
                }
            }
            else
            { // same Year
              // month not the same
                if (!PlayerPrefs.GetInt("month").Equals(System.DateTime.Now.Month))
                {
                    // Add 24 Hour Coins
                    if (PlayerPrefs.GetInt("month") < System.DateTime.Now.Month)
                    {
                        offlineCoinCount = PlayerPrefs.GetInt("OfflineCoinsVal") * (24 * 60);
                    } else {
                        offlineCoinCount = 0;
                    }
                }
                else
                { // Same Month
                  // day not the same
                    if (!PlayerPrefs.GetInt("day").Equals(System.DateTime.Now.Day))
                    {
                        // Add 24 hours?
                        if (PlayerPrefs.GetInt("day") < System.DateTime.Now.Day)
                        {
                            offlineCoinCount = PlayerPrefs.GetInt("OfflineCoinsVal") * (24 * 60);
                        } else {
                            offlineCoinCount = 0;
                        }

                    }
                    else
                    { // Same Day
                      // hour not the same
                        if (!PlayerPrefs.GetInt("timeHour").Equals(System.DateTime.Now.Hour))
                        {
                            // Add Coins
                            if (PlayerPrefs.GetInt("timeHour") < System.DateTime.Now.Hour)
                            {
                                offlineCoinCount = PlayerPrefs.GetInt("OfflineCoinsVal") * (((System.DateTime.Now.Hour - PlayerPrefs.GetInt("timeHour")) * 60) - (System.DateTime.Now.Minute - PlayerPrefs.GetInt("timeMin")));
                            } else {
                                offlineCoinCount = 0;
                            }

                        }
                        else
                        { // Same hour
                          // min not the same
                            if (!PlayerPrefs.GetInt("timeMin").Equals(System.DateTime.Now.Minute))
                            {
                                // Add coins
                                offlineCoinCount = PlayerPrefs.GetInt("OfflineCoinsVal") * (System.DateTime.Now.Minute - PlayerPrefs.GetInt("timeMin"));

                            }
                            else
                            { // Same min

                            }
                        }
                    }
                }
            }
        }

此反时间作弊的代码休息区

private void OnApplicationQuit()
{
    saveDateTime();
    PlayerPrefs.SetInt("offlineCheck", 1);
    //offlineCoinCount = 0;
}


private void OnApplicationFocus(bool focus)
{
    saveDateTime();
    PlayerPrefs.SetInt("offlineCheck", 1);
    //offlineCoinCount = 0;
}
private void OnApplicationPause(bool pause)
{
    saveDateTime();
    PlayerPrefs.SetInt("offlineCheck", 1);
    //offlineCoinCount = 0;
}
public void saveDateTime()
{
    //Player Restart Game
    //////
    /// Check Time for coin bonus
    ////

    if (PlayerPrefs.GetInt("year").Equals(System.DateTime.Now.Year))
    { // Same Year
        if (PlayerPrefs.GetInt("month").Equals(System.DateTime.Now.Month))
        { // Same Month
            if (PlayerPrefs.GetInt("day").Equals(System.DateTime.Now.Day))
            { // Same Day
                if (PlayerPrefs.GetInt("timeHour").Equals(System.DateTime.Now.Hour))
                { // Same Hour
                    if (PlayerPrefs.GetInt("timeMin").Equals(System.DateTime.Now.Minute))
                    { // Same Minute

                    }
                    else
                    { // Different Minute
                        // Update if new Minute is higher than old
                        if (PlayerPrefs.GetInt("timeMin") < System.DateTime.Now.Month)
                        {
                            PlayerPrefs.SetInt("timeMin", System.DateTime.Now.Minute);
                        }
                    }

                }
                else
                { //Different Hour
                    // Update if new hour is higher than old
                    if (PlayerPrefs.GetInt("timeHour") < System.DateTime.Now.Month)
                        PlayerPrefs.SetInt("timeHour", System.DateTime.Now.Hour);
                    PlayerPrefs.SetInt("timeMin", System.DateTime.Now.Minute);
                }
            }
            else
            { // Different Day
              // Update if new day is higher than old
                if (PlayerPrefs.GetInt("day") < System.DateTime.Now.Month)
                {
                    PlayerPrefs.SetInt("day", System.DateTime.Now.Year);
                    PlayerPrefs.SetInt("timeHour", System.DateTime.Now.Hour);
                    PlayerPrefs.SetInt("timeMin", System.DateTime.Now.Minute);
                }
            }

        }
        else
        { // Different Month

            // Update if new month is higher than old
            if (PlayerPrefs.GetInt("month") < System.DateTime.Now.Month)
            {
                PlayerPrefs.SetInt("month", System.DateTime.Now.Year);
                PlayerPrefs.SetInt("day", System.DateTime.Now.Year);
                PlayerPrefs.SetInt("timeHour", System.DateTime.Now.Hour);
                PlayerPrefs.SetInt("timeMin", System.DateTime.Now.Minute);
            }
        }
    }

    else
    { // Different Year
        // Update if new year is higher than old
        if (PlayerPrefs.GetInt("year") < System.DateTime.Now.Year)
        {
            PlayerPrefs.SetInt("year", System.DateTime.Now.Year);
            PlayerPrefs.SetInt("month", System.DateTime.Now.Year);
            PlayerPrefs.SetInt("day", System.DateTime.Now.Year);
            PlayerPrefs.SetInt("timeHour", System.DateTime.Now.Hour);
            PlayerPrefs.SetInt("timeMin", System.DateTime.Now.Minute);
        }
    }
}

0 个答案:

没有答案