コード例 #1
0
        public void GetCDKeyList()
        {
            UPLAY_Overlapped uplay_Overlapped = default(UPLAY_Overlapped);
            IntPtr           intPtr           = Marshal.AllocHGlobal(Marshal.SizeOf(uplay_Overlapped));

            Marshal.StructureToPtr(uplay_Overlapped, intPtr, true);
            overlappedMap.Add(intPtr, uplay_Overlapped);
            IntPtr ptr;
            Int32  num = UplayInvokes.UPLAY_USER_GetCdKeys(out ptr, intPtr);

            if (num != 0)
            {
                UplayInvokes.UPLAY_Update();
                while (!UplayInvokes.UPLAY_HasOverlappedOperationCompleted(intPtr))
                {
                    Thread.Sleep(5);
                    UplayInvokes.UPLAY_Update();
                }
                m_keys.Clear();
                UPLAY_USER_CdKeyList uplay_USER_CdKeyList = (UPLAY_USER_CdKeyList)Marshal.PtrToStructure(ptr, typeof(UPLAY_USER_CdKeyList));
                IntPtr list = uplay_USER_CdKeyList.list;
                for (Int32 i = 0; i < uplay_USER_CdKeyList.count; i++)
                {
                    UPLAY_USER_CdKey uplay_USER_CdKey = (UPLAY_USER_CdKey)Marshal.PtrToStructure(list, typeof(UPLAY_USER_CdKey));
                    m_keys.Add(uplay_USER_CdKey.keyUtf8);
                    list = new IntPtr(list.ToInt32() + IntPtr.Size);
                }
            }
        }
コード例 #2
0
        public void ShowOverlay()
        {
            UPLAY_Overlapped uplay_Overlapped = default(UPLAY_Overlapped);
            IntPtr           intPtr           = Marshal.AllocHGlobal(Marshal.SizeOf(uplay_Overlapped));

            Marshal.StructureToPtr(uplay_Overlapped, intPtr, true);
            overlappedMap.Add(intPtr, uplay_Overlapped);
            UplayInvokes.UPLAY_OVERLAY_Show(UPLAY_OVERLAY_Section.UPLAY_OverlaySection_Show, intPtr);
        }
コード例 #3
0
 public String GetPassword()
 {
     if (m_isUplayConnected)
     {
         IntPtr ptr = UplayInvokes.UPLAY_USER_GetPasswordUtf8();
         return(Marshal.PtrToStringAnsi(ptr));
     }
     return(String.Empty);
 }
コード例 #4
0
 private void WaitForOverlapped(IntPtr p_overlapped)
 {
     UplayInvokes.UPLAY_Update();
     while (!UplayInvokes.UPLAY_HasOverlappedOperationCompleted(p_overlapped))
     {
         Thread.Sleep(5);
         UplayInvokes.UPLAY_Update();
     }
 }
コード例 #5
0
        private void DoneLogin()
        {
            m_isOfflineMode          = (UplayInvokes.UPLAY_USER_IsInOfflineMode() != 0);
            m_isRendezVousConnected  = !m_isOfflineMode;
            m_connectingToRendezVous = false;
            UpdatePrivilegesRewards();
            IntPtr ptr = RendezVousInvokes.LegacyRendezVousGetLocation();

            LegacyLogic.Instance.TrackingManager.TrackGameStart(Marshal.PtrToStringAnsi(ptr));
        }
コード例 #6
0
 public void EarnAchievment(Int32 achievementId)
 {
     if (m_isUplayConnected)
     {
         UPLAY_Overlapped uplay_Overlapped = default(UPLAY_Overlapped);
         IntPtr           intPtr           = Marshal.AllocHGlobal(Marshal.SizeOf(uplay_Overlapped));
         Marshal.StructureToPtr(uplay_Overlapped, intPtr, true);
         overlappedMap.Add(intPtr, uplay_Overlapped);
         Int32 num = UplayInvokes.UPLAY_ACH_EarnAchievement((UInt32)achievementId, intPtr);
         if (num != 0)
         {
         }
     }
 }
コード例 #7
0
 public void Close()
 {
     if (m_isUplayConnected)
     {
         RendezVousInvokes.LegacyRendezVousShutDown();
         UplayInvokes.UPLAY_Quit();
     }
     foreach (IntPtr hglobal in overlappedMap.Keys)
     {
         Marshal.FreeHGlobal(hglobal);
     }
     overlappedMap.Clear();
     LegacyLogic.Instance.EventManager.UnregisterEvent(EEventType.TOKEN_ADDED, new EventHandler(OnTokenAdded));
     LegacyLogic.Instance.EventManager.UnregisterEvent(EEventType.SAVEGAME_LOADED, new EventHandler(OnSaveGameLoaded));
 }
コード例 #8
0
        public void Init()
        {
            String languageCode = GetLanguageCode();

            try
            {
                switch (UplayInvokes.UPLAY_Startup(403u, 9u, languageCode))
                {
                case 0:
                    m_isUplayConnected = true;
                    break;

                case 1:
                {
                    String empty = String.Empty;
                    UplayInvokes.UPLAY_GetLastError(ref empty);
                    Debug.Log("Uplay Error: " + empty);
                    break;
                }

                case 2:
                    m_isForceQuit = true;
                    break;

                case 3:
                    Screen.SetResolution(640, 480, false);
                    m_uplayNotInstalled = true;
                    m_isForceQuit       = true;
                    break;
                }
            }
            catch (Exception exception)
            {
                m_isUplayConnected = false;
                m_isForceQuit      = true;
                Debug.LogException(exception);
                Debug.Log("Exception connecting!");
            }
            if (!m_isForceQuit && m_isUplayConnected)
            {
                SetSaveGameManager();
                ConnectToServer();
                LoadPrivilegesRewards();
            }
            LegacyLogic.Instance.EventManager.RegisterEvent(EEventType.TOKEN_ADDED, new EventHandler(OnTokenAdded));
            LegacyLogic.Instance.EventManager.RegisterEvent(EEventType.SAVEGAME_LOADED, new EventHandler(OnSaveGameLoaded));
        }
コード例 #9
0
        private MemoryStream OpenSaveGame(UPLAY_SAVE_Game p_saveGame)
        {
            IntPtr intPtr = CreateOverlapped();
            UInt32 aSaveHandle;
            Int32  num = UplayInvokes.UPLAY_SAVE_Open(p_saveGame.id, UPLAY_SAVE_Mode.UPLAY_SAVE_MODE_Read, out aSaveHandle, intPtr);

            WaitForOverlapped(intPtr);
            UPLAY_OverlappedResult uplay_OverlappedResult;

            UplayInvokes.UPLAY_GetOverlappedOperationResult(intPtr, out uplay_OverlappedResult);
            if (num == 0 || uplay_OverlappedResult != UPLAY_OverlappedResult.UPLAY_OverlappedResult_Ok)
            {
                m_lastError = ESaveGameError.COULD_NOT_LOAD_SAVEGAME;
                return(null);
            }
            Byte[]         array = new Byte[p_saveGame.size];
            UPLAY_DataBlob uplay_DataBlob;

            uplay_DataBlob.data     = Marshal.AllocHGlobal((Int32)p_saveGame.size);
            uplay_DataBlob.numBytes = p_saveGame.size;
            IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(uplay_DataBlob));

            Marshal.StructureToPtr(uplay_DataBlob, intPtr2, true);
            intPtr = CreateOverlapped();
            UInt32 length;

            num = UplayInvokes.UPLAY_SAVE_Read(aSaveHandle, p_saveGame.size, 0u, intPtr2, out length, intPtr);
            WaitForOverlapped(intPtr);
            UplayInvokes.UPLAY_GetOverlappedOperationResult(intPtr, out uplay_OverlappedResult);
            if (num == 0 || uplay_OverlappedResult != UPLAY_OverlappedResult.UPLAY_OverlappedResult_Ok)
            {
                m_lastError = ESaveGameError.COULD_NOT_LOAD_SAVEGAME;
                return(null);
            }
            uplay_DataBlob = (UPLAY_DataBlob)Marshal.PtrToStructure(intPtr2, typeof(UPLAY_DataBlob));
            Marshal.Copy(uplay_DataBlob.data, array, 0, (Int32)length);
            UplayInvokes.UPLAY_SAVE_Close(aSaveHandle);
            Marshal.FreeHGlobal(uplay_DataBlob.data);
            Marshal.FreeHGlobal(intPtr2);
            Marshal.FreeHGlobal(intPtr);
            return(new MemoryStream(array));
        }
コード例 #10
0
        private Int32 GetSaveGameList(out UPLAY_SAVE_GameList p_saveGameList)
        {
            IntPtr intPtr = CreateOverlapped();
            IntPtr ptr;
            Int32  num = UplayInvokes.UPLAY_SAVE_GetSavegames(out ptr, intPtr);

            WaitForOverlapped(intPtr);
            UPLAY_OverlappedResult uplay_OverlappedResult;

            UplayInvokes.UPLAY_GetOverlappedOperationResult(intPtr, out uplay_OverlappedResult);
            if (uplay_OverlappedResult == UPLAY_OverlappedResult.UPLAY_OverlappedResult_Ok && num != 0)
            {
                p_saveGameList = (UPLAY_SAVE_GameList)Marshal.PtrToStructure(ptr, typeof(UPLAY_SAVE_GameList));
            }
            else
            {
                p_saveGameList = default(UPLAY_SAVE_GameList);
                m_lastError    = ESaveGameError.COULD_NOT_RECEIVE_SAVEGAMES;
                num            = 0;
            }
            Marshal.FreeHGlobal(intPtr);
            return(num);
        }
コード例 #11
0
        public void DeleteSaveGame(String p_file)
        {
            UPLAY_SAVE_GameList uplay_SAVE_GameList;
            Int32 saveGameList = GetSaveGameList(out uplay_SAVE_GameList);

            if (saveGameList != 0)
            {
                IntPtr list = uplay_SAVE_GameList.list;
                for (Int32 i = 0; i < uplay_SAVE_GameList.count; i++)
                {
                    IntPtr          ptr             = Marshal.ReadIntPtr(list, 0);
                    UPLAY_SAVE_Game uplay_SAVE_Game = (UPLAY_SAVE_Game)Marshal.PtrToStructure(ptr, typeof(UPLAY_SAVE_Game));
                    if (uplay_SAVE_Game.nameUtf8 == p_file)
                    {
                        IntPtr intPtr = CreateOverlapped();
                        UplayInvokes.UPLAY_SAVE_Remove(uplay_SAVE_Game.id, intPtr);
                        WaitForOverlapped(intPtr);
                        Marshal.FreeHGlobal(intPtr);
                        break;
                    }
                    list = new IntPtr(list.ToInt32() + IntPtr.Size);
                }
            }
        }
コード例 #12
0
        public void Update()
        {
            if (m_startingRendezVous)
            {
                StartUpState startUpState = (StartUpState)RendezVousInvokes.LegacyRendezVousGetStartUpState();
                if (startUpState == StartUpState.SUCCESSFUL)
                {
                    m_startingRendezVous = false;
                    String userName = GetUserName();
                    String password = GetPassword();
                    GetCDKeyList();
                    if (m_keys.Count > 0)
                    {
                        RendezVousInvokes.LegacyRendezVousLogIn(userName, password, m_keys[0]);
                        m_connectingToRendezVous = true;
                        m_unlockingKeyNr         = -1;
                    }
                }
                else if (startUpState == StartUpState.FAILURE)
                {
                    m_startingRendezVous = false;
                    m_isOfflineMode      = true;
                }
            }
            if (m_connectingToRendezVous)
            {
                if (m_unlockingKeyNr == -1)
                {
                    LogInState logInState = (LogInState)RendezVousInvokes.LegacyRendezVousGetLogInState();
                    if (logInState == LogInState.SUCCESSFUL)
                    {
                        m_unlockingKeyNr = 0;
                        RendezVousInvokes.LegacyRendezVousActivateAnyKey(m_keys[m_unlockingKeyNr]);
                    }
                    else if (logInState == LogInState.FAILURE)
                    {
                        m_isOfflineMode          = true;
                        m_connectingToRendezVous = false;
                    }
                }
                else
                {
                    EActivateKeyResult unlockPrivilegeState = GetUnlockPrivilegeState();
                    if (unlockPrivilegeState != EActivateKeyResult.ACTIVATE_WAITING)
                    {
                        m_unlockingKeyNr++;
                        if (m_unlockingKeyNr < m_keys.Count)
                        {
                            RendezVousInvokes.LegacyRendezVousActivateAnyKey(m_keys[m_unlockingKeyNr]);
                        }
                        else
                        {
                            DoneLogin();
                        }
                    }
                }
            }
            if (m_isSettingAction)
            {
                SetActionState setActionState = (SetActionState)RendezVousInvokes.LegacyRendezVousGetActionsState();
                if (setActionState == SetActionState.SUCCESSFUL)
                {
                    if (OnActionCompleted != null && m_settingActionID >= 0)
                    {
                        ActionCompletedEventArgs e = new ActionCompletedEventArgs(m_settingActionID, true);
                        OnActionCompleted(this, e);
                    }
                    m_isSettingAction = false;
                    m_settingActionID = -1;
                }
                else if (setActionState == SetActionState.FAILURE)
                {
                    if (OnActionCompleted != null && m_settingActionID >= 0)
                    {
                        ActionCompletedEventArgs e2 = new ActionCompletedEventArgs(m_settingActionID, false);
                        OnActionCompleted(this, e2);
                    }
                    m_isSettingAction = false;
                    m_settingActionID = -1;
                }
            }
            List <IntPtr> list = new List <IntPtr>();

            foreach (IntPtr intPtr in overlappedMap.Keys)
            {
                if (UplayInvokes.UPLAY_HasOverlappedOperationCompleted(intPtr))
                {
                    list.Add(intPtr);
                }
            }
            foreach (IntPtr intPtr2 in list)
            {
                overlappedMap.Remove(intPtr2);
                Marshal.FreeHGlobal(intPtr2);
            }
            list.Clear();
            if (UplayInvokes.UPLAY_Update() == 0)
            {
                m_isForceQuit = true;
            }
            UPLAY_Event uplay_Event;

            while (UplayInvokes.UPLAY_GetNextEvent(out uplay_Event))
            {
                Debug.Log("Received uplay Event! : " + uplay_Event.type);
                if (uplay_Event.type == UPLAY_EventType.UPLAY_Event_UserAccountSharing)
                {
                    m_isRendezVousConnected = false;
                    m_isOfflineMode         = true;
                }
            }
        }
コード例 #13
0
        public void SaveSaveGame(SaveGame p_saveGame, String p_file, Byte[] p_screenshot)
        {
            UInt32 num = 0u;

            m_usedSlots.Clear();
            UPLAY_SAVE_GameList uplay_SAVE_GameList;
            Int32 num2 = GetSaveGameList(out uplay_SAVE_GameList);

            if (num2 != 0)
            {
                IntPtr list = uplay_SAVE_GameList.list;
                for (Int32 i = 0; i < uplay_SAVE_GameList.count; i++)
                {
                    IntPtr          ptr             = Marshal.ReadIntPtr(list, 0);
                    UPLAY_SAVE_Game uplay_SAVE_Game = (UPLAY_SAVE_Game)Marshal.PtrToStructure(ptr, typeof(UPLAY_SAVE_Game));
                    if (uplay_SAVE_Game.nameUtf8 == p_file)
                    {
                        num = uplay_SAVE_Game.id;
                        break;
                    }
                    m_usedSlots.Add(uplay_SAVE_Game.id);
                    list = new IntPtr(list.ToInt32() + IntPtr.Size);
                }
            }
            if (num == 0u)
            {
                if (LegacyLogic.Instance.WorldManager.CurrentSaveGameType == ESaveGameType.AUTO)
                {
                    num = 1u;
                }
                else if (LegacyLogic.Instance.WorldManager.CurrentSaveGameType == ESaveGameType.QUICK)
                {
                    num = 2u;
                }
                else
                {
                    UInt32 num3 = 11u;
                    while (num != num3)
                    {
                        num = num3;
                        for (Int32 j = 0; j < m_usedSlots.Count; j++)
                        {
                            if (num == m_usedSlots[j])
                            {
                                num   = 0u;
                                num3 += 1u;
                                break;
                            }
                        }
                    }
                }
            }
            IntPtr intPtr = CreateOverlapped();
            UInt32 aSaveHandle;

            num2 = UplayInvokes.UPLAY_SAVE_Open(num, UPLAY_SAVE_Mode.UPLAY_SAVE_MODE_Write, out aSaveHandle, intPtr);
            WaitForOverlapped(intPtr);
            UPLAY_OverlappedResult uplay_OverlappedResult;

            UplayInvokes.UPLAY_GetOverlappedOperationResult(intPtr, out uplay_OverlappedResult);
            if (num2 == 0 || uplay_OverlappedResult != UPLAY_OverlappedResult.UPLAY_OverlappedResult_Ok)
            {
                m_lastError = ESaveGameError.COULD_NOT_SAVE_SAVEGAME;
                return;
            }
            UplayInvokes.UPLAY_SAVE_SetName(aSaveHandle, p_file);
            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
                {
                    p_saveGame.Write(binaryWriter);
                    if (p_screenshot != null)
                    {
                        binaryWriter.Write(p_screenshot.Length);
                        binaryWriter.Write(p_screenshot);
                    }
                    else
                    {
                        binaryWriter.Write(0);
                    }
                }
                Byte[]         array = memoryStream.ToArray();
                UPLAY_DataBlob uplay_DataBlob;
                uplay_DataBlob.data     = Marshal.AllocHGlobal(array.Length);
                uplay_DataBlob.numBytes = (UInt32)array.Length;
                IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(uplay_DataBlob));
                Marshal.Copy(array, 0, uplay_DataBlob.data, array.Length);
                Marshal.StructureToPtr(uplay_DataBlob, intPtr2, true);
                num2 = UplayInvokes.UPLAY_SAVE_Write(aSaveHandle, (UInt32)array.Length, intPtr2, intPtr);
                WaitForOverlapped(intPtr);
                UplayInvokes.UPLAY_GetOverlappedOperationResult(intPtr, out uplay_OverlappedResult);
                if (num2 == 0 || uplay_OverlappedResult != UPLAY_OverlappedResult.UPLAY_OverlappedResult_Ok)
                {
                    m_lastError = ESaveGameError.COULD_NOT_SAVE_SAVEGAME;
                }
            }
            UplayInvokes.UPLAY_SAVE_Close(aSaveHandle);
            Marshal.FreeHGlobal(intPtr);
        }