/* This method reads a specified file from your hard-drive and copies it to local storage. * Please note that you can use Galaxy SDK FileWrite method to write bytes from memory to a * file in local storage i.e. create new file instead of copying an existing one. */ public void CopyFileToLocalStorage(string absoluteInputPath) { string fileName = null; byte[] data = null; if (File.Exists(absoluteInputPath)) { fileName = Path.GetFileName(absoluteInputPath); data = File.ReadAllBytes(absoluteInputPath); } else { Debug.Log("File " + absoluteInputPath + " does not exist"); return; } try { Debug.Log("Writing file " + absoluteInputPath + " to local storage."); GalaxyInstance.Storage().FileWrite(fileName, data, (uint)data.Length); } catch (GalaxyInstance.Error e) { Debug.LogWarning("Could not write file " + absoluteInputPath + " to local storage for reason: " + e); } }
protected override void connectImpl() { this.client = new GalaxySocket(ModCore.multiplayer.protocolVersion); GalaxyInstance.User().GetGalaxyID(); this.client.JoinLobby(this.lobbyId); ModCore.monitor.Log("Success on generating modded galaxy client."); }
public override void OnLeaderboardEntriesRetrieveSuccess(string leaderboardName, uint entryCount) { Debug.Log("Leaderboard \"" + leaderboardName + "\" entries retrieved\nEntry count: " + entryCount); leaderboardEntries.Clear(); leaderboardEntries.TrimExcess(); for (uint i = 0; i < entryCount; i++) { GalaxyID userID = new GalaxyID(); uint rank = 0; int score = 0; string username = null; object[] entryDetails = new object[] { rank, score, username }; GalaxyInstance.Stats().GetRequestedLeaderboardEntry(i, ref rank, ref score, ref userID); username = GalaxyManager.Instance.Friends.GetFriendPersonaName(userID); entryDetails[0] = rank; entryDetails[1] = score; entryDetails[2] = username; Debug.Log("Created object #" + i + " | " + rank + " | " + score + " | " + username); leaderboardEntries.Add(entryDetails); } if (GameObject.Find("LeaderboardsScreen")) { GameObject.Find("LeaderboardsScreen").GetComponent <LeaderboardsController>().DisplayLeaderboard(); } }
// Gets username of a user currently signed in to GOG Galaxy Client public string GetMyUsername(bool silent = false) { if (!silent) { Debug.Log("Looking up current user name..."); } string username = ""; try { username = GalaxyInstance.Friends().GetPersonaName(); if (!silent) { Debug.Log("Current user name: " + username); } } catch (GalaxyInstance.Error e) { if (!silent) { Debug.LogError("Failed to get current user name for reason " + e); } } return(username); }
// Token: 0x06000029 RID: 41 RVA: 0x0000281E File Offset: 0x00000A1E public static void update() { if (GOGHelper.active) { GalaxyInstance.ProcessData(); } }
// Gets a lobby message public string GetLobbyMessage(GalaxyID lobbyID, ref GalaxyID senderID, uint messageID) { string message = null; GalaxyInstance.Matchmaking().GetLobbyMessage(lobbyID, messageID, ref senderID, out message); return(message); }
public void Update() { if (active) { GalaxyInstance.ProcessData(); } }
private void onGalaxyLobbyEnter(GalaxyID lobbyID, LobbyEnterResult result) { connectingLobbyID = null; if (result != 0) { return; } Console.WriteLine("Lobby entered: {0}", lobbyID.ToUint64()); lobby = lobbyID; lobbyOwner = GalaxyInstance.Matchmaking().GetLobbyOwner(lobbyID); if (Game1.chatBox != null) { string invite_code_string = ""; if (Program.sdk.Networking != null && Program.sdk.Networking.SupportsInviteCodes()) { invite_code_string = Game1.content.LoadString("Strings\\UI:Chat_LobbyJoined_InviteCode", GetInviteCode()); } if (isRecreatedLobby) { Game1.chatBox.addInfoMessage(Game1.content.LoadString("Strings\\UI:Chat_LobbyRecreated", invite_code_string).Trim()); } else { Game1.chatBox.addInfoMessage(Game1.content.LoadString("Strings\\UI:Chat_LobbyJoined", invite_code_string).Trim()); } } if (lobbyOwner == selfId) { foreach (KeyValuePair <string, string> pair in lobbyData) { GalaxyInstance.Matchmaking().SetLobbyData(lobby, pair.Key, pair.Value); } updateLobbyPrivacy(); } }
/* Checks if user is logged on * NOTE: Logged on means that the user is signed in to GOG Galaxy client and he does have working internet connection */ public bool IsLoggedOn(bool silent = false) { bool isLoggedOn = false; if (!silent) { Debug.Log("Checking LoggedOn status..."); } try { isLoggedOn = GalaxyInstance.User().IsLoggedOn(); if (!silent) { Debug.Log("User logged on: " + isLoggedOn); } } catch (GalaxyInstance.Error e) { if (!silent) { Debug.LogWarning("Could not check user logged on status for reason " + e); } } return(isLoggedOn); }
public void Initialize() { try { active = SteamAPI.Init(); Console.WriteLine("Steam logged on: " + SteamUser.BLoggedOn().ToString()); if (active) { Console.WriteLine("Initializing GalaxySDK"); GalaxyInstance.Init(new InitParams("48767653913349277", "58be5c2e55d7f535cf8c4b6bbc09d185de90b152c8c42703cc13502465f0d04a", ".")); encryptedAppTicketResponse = CallResult <EncryptedAppTicketResponse_t> .Create(onEncryptedAppTicketResponse); galaxyAuthListener = new GalaxyHelper.AuthListener(onGalaxyAuthSuccess, onGalaxyAuthFailure, onGalaxyAuthLost); galaxyStateChangeListener = new GalaxyHelper.OperationalStateChangeListener(onGalaxyStateChange); Console.WriteLine("Requesting Steam app ticket"); SteamAPICall_t handle = SteamUser.RequestEncryptedAppTicket(new byte[0], 0); encryptedAppTicketResponse.Set(handle); ConnectionProgress++; } } catch (Exception value) { Console.WriteLine(value); active = false; ConnectionFinished = true; } if (active) { gameOverlayActivated = Callback <GameOverlayActivated_t> .Create(onGameOverlayActivated); gamepadTextInputDismissed = Callback <GamepadTextInputDismissed_t> .Create(OnKeyboardDismissed); } }
/* Checks current user singed in status * NOTE: Signed in means that the user is signed in to GOG Galaxy client (he does not have to have working internet connection). */ public bool IsSignedIn(bool silent = false) { bool signedIn = false; if (!silent) { Debug.Log("Checking SignedIn status..."); } try { signedIn = GalaxyInstance.User().SignedIn(); if (!silent) { Debug.Log("User SignedIn: " + signedIn); } } catch (GalaxyInstance.Error e) { if (!silent) { Debug.LogWarning("Could not check user signed in status for reason " + e); } } return(signedIn); }
public void Send(GalaxyID peer, byte[] data) { if (!connections.ContainsKey(peer.ToUint64())) { return; } if (data.Length <= 1100) { byte[] packet2 = new byte[data.Length + 4]; data.CopyTo(packet2, 4); GalaxyInstance.Networking().SendP2PPacket(peer, packet2, (uint)packet2.Length, P2PSendType.P2P_SEND_RELIABLE); return; } int chunkSize = 1096; int messageOffset = 0; byte[] packet = new byte[1100]; packet[0] = 1; while (messageOffset < data.Length) { int thisChunkSize = chunkSize; if (messageOffset + chunkSize >= data.Length) { packet[0] = 0; thisChunkSize = data.Length - messageOffset; } Buffer.BlockCopy(data, messageOffset, packet, 4, thisChunkSize); messageOffset += thisChunkSize; GalaxyInstance.Networking().SendP2PPacket(peer, packet, (uint)(thisChunkSize + 4), P2PSendType.P2P_SEND_RELIABLE); } }
public virtual string GetLobbyOwnerName(object lobbyId) { GalaxyID lobby = new GalaxyID((ulong)lobbyId); GalaxyID owner = GalaxyInstance.Matchmaking().GetLobbyOwner(lobby); return(GalaxyInstance.Friends().GetFriendPersonaName(owner)); }
public IEnumerable <GalaxyID> LobbyMembers() { if (lobby == null) { yield break; } uint lobby_members_count; try { lobby_members_count = GalaxyInstance.Matchmaking().GetNumLobbyMembers(lobby); } catch (Exception) { yield break; } uint i = 0u; while (i < lobby_members_count) { GalaxyID lobbyMember = GalaxyInstance.Matchmaking().GetLobbyMemberByIndex(lobby, i); if (!(lobbyMember == selfId) && !ghosts.Contains(lobbyMember.ToUint64())) { yield return(lobbyMember); } uint num = i + 1; i = num; } }
private void updateLobbyPrivacy() { if (lobbyOwner != selfId) { return; } if (lobby != null) { GalaxyInstance.Matchmaking().SetLobbyType(lobby, privacyToLobbyType(privacy)); } if (lobby == null) { if (steamLobby.HasValue) { SteamMatchmaking.LeaveLobby(steamLobby.Value); } } else if (!steamLobby.HasValue) { if (steamLobbyEnterCallback == null) { steamLobbyEnterCallback = Callback <LobbyEnter_t> .Create(onSteamLobbyEnter); } SteamMatchmaking.CreateLobby(privacyToSteamLobbyType(privacy), (int)memberLimit); } else { SteamMatchmaking.SetLobbyType(steamLobby.Value, privacyToSteamLobbyType(privacy)); SteamMatchmaking.SetLobbyData(steamLobby.Value, "connect", getConnectionString()); } }
public void ResetAchievements() { if (active) { GalaxyInstance.Stats().ResetStatsAndAchievements(); } }
public static void UpdateServerTick(GalaxyID id) { try { var mm = GalaxyInstance.Matchmaking(); int numberOfPlayers = Game1.getOnlineFarmers().Count; int numberOfPlayerSlots = -1; try { Multiplayer mp = ModEntry.ModHelper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue(); numberOfPlayerSlots = mp.playerLimit; } catch (Exception) { } int freeCabins = GetCabinsInsides().Where(x => x.owner == null || x.owner.Name.Length == 0).Count(); mm.SetLobbyData(id, "numberOfPlayers", numberOfPlayers.ToString()); mm.SetLobbyData(id, "numberOfPlayerSlots", numberOfPlayerSlots.ToString()); mm.SetLobbyData(id, "freeCabins", freeCabins.ToString()); } catch (Exception) { Console.WriteLine("Could not update server metadata - likely because the world is not yet initialised"); } }
public static void InnitServer(GalaxyID id) { Console.WriteLine("Initialising server metadata"); var mm = GalaxyInstance.Matchmaking(); string serverBrowserVersion = ModEntry.ModHelper.ModRegistry.Get("Ilyaki.ServerBrowser").Manifest.Version.ToString(); mm.SetLobbyData(id, "serverBrowserVersion", serverBrowserVersion); string serverMessage = ModEntry.Config.ServerMessage; mm.SetLobbyData(id, "serverMessage", serverMessage); StringBuilder sb = new StringBuilder(); foreach (var modID in ModEntry.Config.RequiredMods) { sb.Append(modID); sb.Append(','); } mm.SetLobbyData(id, "requiredMods", sb.ToString()); sb.Clear(); foreach (var modID in ModEntry.ModHelper.ModRegistry.GetAll().Select(x => x.Manifest.UniqueID)) { sb.Append(modID); sb.Append(','); } mm.SetLobbyData(id, "serverMods", sb.ToString()); string password = ModEntry.Config.Password; mm.SetLobbyData(id, "password", password); }
private void tryCreateLobby() { Console.WriteLine("Creating lobby..."); galaxyLobbyLeftCallback = new GalaxyLobbyLeftListener(onGalaxyLobbyLeft); GalaxyInstance.Matchmaking().CreateLobby(privacyToLobbyType(privacy), memberLimit, joinable: true, LobbyTopologyType.LOBBY_TOPOLOGY_TYPE_STAR); recreateTimer = 0L; }
public AuthListener(Action success, Action <FailureReason> failure, Action lost) { OnSuccess = success; OnFailure = failure; OnLost = lost; GalaxyInstance.ListenerRegistrar().Register(GalaxyTypeAwareListenerAuth.GetListenerType(), this); }
public GalaxySocket(string protocolVersion) { this.protocolVersion = protocolVersion; lobbyData["protocolVersion"] = protocolVersion; selfId = GalaxyInstance.User().GetGalaxyID(); galaxyLobbyEnterCallback = new GalaxyLobbyEnteredListener(onGalaxyLobbyEnter); galaxyLobbyCreatedCallback = new GalaxyLobbyCreatedListener(onGalaxyLobbyCreated); }
private void onPersonaDataChanged(GalaxyID userID, uint avatarCriteria) { if (peers.ContainsRight(userID.ToUint64())) { long farmerID = peers.GetLeft(userID.ToUint64()); Game1.multiplayer.broadcastUserName(farmerID, GalaxyInstance.Friends().GetFriendPersonaName(userID)); } }
public override void initialize() { Console.WriteLine("Starting Galaxy server"); host = GalaxyInstance.User().GetGalaxyID(); galaxyPersonaDataChangedListener = new GalaxyPersonaDataChangedListener(onPersonaDataChanged); server = new GalaxySocket("1.5.1"); server.CreateLobby(Game1.options.serverPrivacy, (uint)(Game1.multiplayer.playerLimit * 2)); }
public void SetLobbyData(string key, string value) { lobbyData[key] = value; if (lobby != null) { GalaxyInstance.Matchmaking().SetLobbyData(lobby, key, value); } }
void OnDestroy() { /* Shuts down the working instance of GalaxyPeer. * NOTE: Shutdown should be the last method called, and all listeners should be closed before that. */ GalaxyInstance.Shutdown(true); Instance = null; Destroy(this); }
public void Update() { if (active) { SteamAPI.RunCallbacks(); GalaxyInstance.ProcessData(); } }
private void onRichPresenceUpdated(GalaxyID userID) { GalaxyID lobby = parseConnectionString(GalaxyInstance.Friends().GetRichPresence("connect", userID)); if (lobby != null) { GalaxyInstance.Matchmaking().RequestLobbyData(lobby); } }
public override string getUserName(long farmerId) { if (!peers.ContainsLeft(farmerId)) { return(null); } GalaxyID user = new GalaxyID(peers[farmerId]); return(GalaxyInstance.Friends().GetFriendPersonaName(user)); }
private void LobbyCreated(GalaxyID lobbyID) { matchmaking.SetLobbyData(lobbyID, "name", matchmaking.lobbyName); matchmaking.SetLobbyData(lobbyID, "state", "notReady"); matchmaking.CurrentLobbyID = lobbyID; matchmaking.LobbyOwnerID = GalaxyInstance.Matchmaking().GetLobbyOwner(lobbyID); matchmaking.SetLobbyMemberData("state", "notReady"); GameObject.Find("MainMenu").GetComponent <MainMenuController>().SwitchMenu(MainMenuController.MenuEnum.OnlineWait); }
public virtual void RequestFriendLobbyData() { uint count = GalaxyInstance.Friends().GetFriendCount(); for (uint i = 0u; i < count; i++) { GalaxyID friend = GalaxyInstance.Friends().GetFriendByIndex(i); GalaxyInstance.Friends().RequestRichPresence(friend); } }