예제 #1
0
        public void SetGameYear(int gameYear, string gameExecutableFilePath)
        {
            // Calculate adjustment and invert sign
            // e.g. if changing game year from 1998 to 2001, 1998-2001 = -3 = 3
            // e.g. if changing game year from 1998 to 1995, 1998-1995 = 3 = -3
            var adjustment = 1998 - gameYear;

            adjustment = -adjustment;

            // Game year of 2001 will now have an adjustment value of 3
            // Game year of 1995 will now have an adjustment value of -3

            var year1996 = 1996 + adjustment; // Effective game year value for 1996 is 1993/1999
            var year1997 = 1997 + adjustment; // Effective game year value for 1997 is 1994/2000
            var year1998 = 1998 + adjustment; // Effective game year value for 1998 is 1995/2001
            var year1999 = 1999 + adjustment; // Effective game year value for 1999 is 1996/2002
            var year2007 = 2007 + adjustment;

            // Get first leap year from game starting year
            var firstLeapYear = 0;

            for (var i = gameYear; i < gameYear + 10; i++)
            {
                if (DateTime.IsLeapYear(i))
                {
                    firstLeapYear = i;
                    break;
                }
            }
            var secondLeapYear = firstLeapYear + 4;
            var thirdLeapYear  = secondLeapYear + 4;
            var fourthLeapYear = thirdLeapYear + 4;

            var yearAfterFirstLeapYear  = firstLeapYear + 1;
            var yearAfterSecondLeapYear = secondLeapYear + 1;

            var gameStartDayOfWeek = (int)new DateTime(gameYear, 1, 1).DayOfWeek;

            if (gameStartDayOfWeek == 0) // If Sunday
            {
                gameStartDayOfWeek = 7;  // Make Sunday the 7th day to match DayOfWeek logic used in the game
            }

            int gameStartDate;
            var date = 8; // The 8 in Sunday 8th March 1998 (default game start date)

            while (true)
            {
                // If the game start date using new gameYear value is not a Sunday, increment date
                // e.g. for 1999, the next Sunday after 8th March is 14th March
                if (new DateTime(gameYear, 3, date).DayOfWeek != DayOfWeek.Sunday)
                {
                    date++;
                }
                else
                {
                    // Set start date to be a date that is a Sunday
                    gameStartDate = date;
                    break;
                }
            }

            // The day of the week naturally increments each year for 1st January (e.g 1998 = Thursday, 1999 = Friday)
            // But when the year follows a leap year, the day of the week should be incremented by two.
            // e.g. if 2000 is a leap year and started on a Saturday, then 2001 starts on a Monday
            // e.g. if 2004 is a leap year and started on a Thursday, then 2005 starts on a Saturday
            // Note, where there are three leap years in a ten-year period, the day of the week will
            // fall behind by one day as the game code only increments the day of the week twice, as
            // it was assumed that there would only ever be two leap years between 1998-2007.

            // Update all values affected by change in game year
            using (var executableConnection = new ExecutableConnection(gameExecutableFilePath))
            {
                executableConnection.WriteByte(GameStartDateOffset, (byte)gameStartDate);
                executableConnection.WriteInteger(GameStartDayOfWeekOffset, gameStartDayOfWeek);

                executableConnection.WriteInteger(GameYear199601Offset, year1996);
                executableConnection.WriteInteger(GameYear199602Offset, year1996);
                executableConnection.WriteInteger(GameYear199603Offset, year1996);
                executableConnection.WriteInteger(GameYear199604Offset, year1996);
                executableConnection.WriteInteger(GameYear199605Offset, year1996);

                executableConnection.WriteInteger(GameYear199701Offset, year1997);
                executableConnection.WriteInteger(GameYear199702Offset, year1997);
                executableConnection.WriteInteger(GameYear199703Offset, year1997);
                executableConnection.WriteInteger(GameYear199704Offset, year1997);
                executableConnection.WriteInteger(GameYear199705Offset, year1997);
                executableConnection.WriteInteger(GameYear199706Offset, year1997);
                executableConnection.WriteInteger(GameYear199707Offset, year1997);
                executableConnection.WriteInteger(GameYear199708Offset, year1997);
                executableConnection.WriteInteger(GameYear199709Offset, year1997);
                executableConnection.WriteInteger(GameYear199710Offset, year1997);
                executableConnection.WriteInteger(GameYear199711Offset, year1997);
                executableConnection.WriteInteger(GameYear199712Offset, year1997);
                executableConnection.WriteInteger(GameYear199713Offset, year1997);
                executableConnection.WriteInteger(GameYear199714Offset, year1997);
                executableConnection.WriteInteger(GameYear199715Offset, year1997);
                executableConnection.WriteInteger(GameYear199716Offset, year1997);
                executableConnection.WriteInteger(GameYear199717Offset, year1997);
                executableConnection.WriteInteger(GameYear199718Offset, year1997);
                executableConnection.WriteInteger(GameYear199719Offset, year1997);
                executableConnection.WriteInteger(GameYear199720Offset, year1997);
                executableConnection.WriteInteger(GameYear199721Offset, year1997);
                executableConnection.WriteInteger(GameYear199722Offset, year1997);
                executableConnection.WriteInteger(GameYear199723Offset, year1997);
                executableConnection.WriteInteger(GameYear199724Offset, year1997);
                executableConnection.WriteInteger(GameYear199725Offset, year1997);
                executableConnection.WriteInteger(GameYear199726Offset, year1997);
                executableConnection.WriteInteger(GameYear199727Offset, year1997);
                executableConnection.WriteInteger(GameYear199728Offset, year1997);
                executableConnection.WriteInteger(GameYear199729Offset, year1997);

                executableConnection.WriteInteger(GameYear199801Offset, year1998);
                executableConnection.WriteInteger(GameYear199802Offset, year1998);
                executableConnection.WriteInteger(GameYear199803Offset, year1998);
                executableConnection.WriteInteger(GameYear199804Offset, year1998);
                executableConnection.WriteInteger(GameYear199805Offset, year1998);
                executableConnection.WriteInteger(GameYear199806Offset, year1998);
                executableConnection.WriteInteger(GameYear199807Offset, year1998);
                executableConnection.WriteInteger(GameYear199808Offset, year1998);
                executableConnection.WriteInteger(GameYear199809Offset, year1998);
                executableConnection.WriteInteger(GameYear199810Offset, year1998);
                executableConnection.WriteInteger(GameYear199811Offset, year1998);
                executableConnection.WriteInteger(GameYear199812Offset, year1998);
                executableConnection.WriteInteger(GameYear199813Offset, year1998);
                executableConnection.WriteInteger(GameYear199814Offset, year1998);
                executableConnection.WriteInteger(GameYear199815Offset, year1998);
                executableConnection.WriteInteger(GameYear199816Offset, year1998);
                executableConnection.WriteInteger(GameYear199817Offset, year1998);
                executableConnection.WriteInteger(GameYear199818Offset, year1998);
                executableConnection.WriteInteger(GameYear199819Offset, year1998);
                executableConnection.WriteInteger(GameYear199820Offset, year1998);
                executableConnection.WriteInteger(GameYear199821Offset, year1998);

                executableConnection.WriteInteger(GameYear199901Offset, year1999);
                executableConnection.WriteInteger(GameYear199902Offset, year1999);

                executableConnection.WriteInteger(GameYear200001Offset, firstLeapYear);
                executableConnection.WriteInteger(GameYear200002Offset, firstLeapYear);
                executableConnection.WriteInteger(GameYear200003Offset, firstLeapYear);

                executableConnection.WriteInteger(GameYear200101Offset, yearAfterFirstLeapYear);

                executableConnection.WriteInteger(GameYear200401Offset, secondLeapYear);
                executableConnection.WriteInteger(GameYear200402Offset, secondLeapYear);
                executableConnection.WriteInteger(GameYear200403Offset, secondLeapYear);

                executableConnection.WriteInteger(GameYear200501Offset, yearAfterSecondLeapYear);

                executableConnection.WriteInteger(GameYear200701Offset, year2007);
                executableConnection.WriteInteger(GameYear200702Offset, year2007);

                executableConnection.WriteInteger(GameYear200801Offset, thirdLeapYear);

                executableConnection.WriteInteger(GameYear201201Offset, fourthLeapYear);
            }
        }