private static void Run_SetupUserCharacterMaster(On.RoR2.Run.orig_SetupUserCharacterMaster orig, Run self, NetworkUser user) { // This method always throws null reference exception for new player joining after game starts, but not when called // called again to spawn the player in after they use the join_as command // This method throwing an uncaught exception causes the following lines in NetworkUser.Start not to be called: // //if (NetworkClient.active) //{ // SyncLunarCoinsToServer(); // SendServerUnlockables(); //} // //OnLoadoutUpdated(); //NetworkUser.onPostNetworkUserStart?.Invoke(this); //if (base.isLocalPlayer && (bool)Stage.instance) //{ // CallCmdAcknowledgeStage(Stage.instance.netId); //} // // Which I believe causes issues like skins not being displayed to other users correct (OnLoadoutUpdated()) // So we are just going to go ahead and catch the exception. As far as I am aware this error is not caused by DropInMultiplayer being installed // If anyone reads this and knows what causes this issue or a better fix for the issue feel free to send me a message try { orig(self, user); } catch (Exception ex) { Debug.LogException(ex); Logger.LogError(ex); Logger.LogMessage("SetupUserCharacterMaster threw an exception and was caught"); } }
private void GiveItems(On.RoR2.Run.orig_SetupUserCharacterMaster orig, Run run, NetworkUser user) { orig(run, user); if (!DropInConfig.StartWithItems || run.fixedTime < 5f) // Don't try to give items to players who spawn with the server { return; } if (DropInConfig.GiveExactItems) { ItemsHelper.CopyItemsFromRandom(user); } else { ItemsHelper.GiveAveragedItems(user, DropInConfig.GiveRedItems, DropInConfig.GiveLunarItems, DropInConfig.GiveBossItems); } }
private void GiveItems(On.RoR2.Run.orig_SetupUserCharacterMaster orig, Run run, NetworkUser user) { orig(run, user); if (!_config.StartWithItems || !run.isServer || // If we are not the server don't try to give items, let the server handle it run.fixedTime < 5f) // Don't try to give items to players who spawn with the server { return; } if (_config.GiveExactItems) { Debug.Log("Giving exact items"); ItemsHelper.CopyItemsFromRandom(user); } else { Debug.Log("Giving averaged items"); ItemsHelper.GiveAveragedItems(user, _config.GiveRedItems, _config.GiveLunarItems, _config.GiveBossItems); } }
private void SetupUserCharacterMaster(On.RoR2.Run.orig_SetupUserCharacterMaster orig, Run self, NetworkUser user) { orig(self, user); if (!StartWithItems.Value || Run.instance.fixedTime < 5f) { return; } int averageItemCountT1 = 0; int averageItemCountT2 = 0; int averageItemCountT3 = 0; ReadOnlyCollection <NetworkUser> readOnlyInstancesList = NetworkUser.readOnlyInstancesList; int playerCount = PlayerCharacterMasterController.instances.Count; if (playerCount <= 1) { return; } else { playerCount--; } for (int i = 0; i < readOnlyInstancesList.Count; i++) { if (readOnlyInstancesList[i].id.Equals(user.id)) { continue; } CharacterMaster cm = readOnlyInstancesList[i].master; averageItemCountT1 += cm.inventory.GetTotalItemCountOfTier(ItemTier.Tier1); averageItemCountT2 += cm.inventory.GetTotalItemCountOfTier(ItemTier.Tier2); averageItemCountT3 += cm.inventory.GetTotalItemCountOfTier(ItemTier.Tier3); } averageItemCountT1 /= playerCount; averageItemCountT2 /= playerCount; averageItemCountT3 /= playerCount; CharacterMaster characterMaster = user.master; int itemCountT1 = averageItemCountT1 - characterMaster.inventory.GetTotalItemCountOfTier(ItemTier.Tier1); int itemCountT2 = averageItemCountT2 - characterMaster.inventory.GetTotalItemCountOfTier(ItemTier.Tier2); int itemCountT3 = averageItemCountT3 - characterMaster.inventory.GetTotalItemCountOfTier(ItemTier.Tier3); itemCountT1 = itemCountT1 < 0 ? 0 : itemCountT1; itemCountT2 = itemCountT2 < 0 ? 0 : itemCountT2; itemCountT3 = itemCountT3 < 0 ? 0 : itemCountT3; Debug.Log(itemCountT1 + " " + itemCountT2 + " " + itemCountT3 + " itemcount to add"); Debug.Log(averageItemCountT1 + " " + averageItemCountT2 + " " + averageItemCountT3 + " average"); for (int i = 0; i < itemCountT1; i++) { characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.tier1ItemList), 1); } for (int i = 0; i < itemCountT2; i++) { characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.tier2ItemList), 1); } for (int i = 0; i < itemCountT3; i++) { characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.tier3ItemList), 1); } }
private void GiveItems(On.RoR2.Run.orig_SetupUserCharacterMaster orig, Run self, NetworkUser user) { orig(self, user); /* * ********************************************************************** * more or less copied from https://github.com/xiaoxiao921/DropInMultiplayer/blob/master/DropInMultiplayerFix/Main.cs * ********************************************************************** */ if (!StartWithItems.Value || Run.instance.fixedTime < 5f) { return; } //the way i did this is confusing so i'm just gonna explain these int names /* * averageItemCountT1 = average item count tier 1 * averageItemCountT2 = average item count tier 2 * averageItemCountT3 = average item count tier 3 * averageItemCountTL = average item count tier lunar * averageItemCountTB = average item count tier boss * yes i do know lunar isn't really a tier but shhhhhhhhhhh */ int averageItemCountT1 = 0; int averageItemCountT2 = 0; int averageItemCountT3 = 0; int averageItemCountTL = 0; // int averageItemCountTB = 0; ReadOnlyCollection <NetworkUser> readOnlyInstancesList = NetworkUser.readOnlyInstancesList; int playerCount = PlayerCharacterMasterController.instances.Count; if (playerCount <= 1) { return; } else { playerCount--; } for (int i = 0; i < readOnlyInstancesList.Count; i++) { if (readOnlyInstancesList[i].id.Equals(user.id)) { continue; } CharacterMaster cm = readOnlyInstancesList[i].master; averageItemCountT1 += cm.inventory.GetTotalItemCountOfTier(ItemTier.Tier1); averageItemCountT2 += cm.inventory.GetTotalItemCountOfTier(ItemTier.Tier2); averageItemCountT3 += cm.inventory.GetTotalItemCountOfTier(ItemTier.Tier3); averageItemCountTL += cm.inventory.GetTotalItemCountOfTier(ItemTier.Lunar); // averageItemCountTB += cm.inventory.GetTotalItemCountOfTier(ItemTier.Boss); } averageItemCountT1 /= playerCount; averageItemCountT2 /= playerCount; averageItemCountT3 /= playerCount; averageItemCountTL /= playerCount; // averageItemCountTB /= playerCount; CharacterMaster characterMaster = user.master; int itemCountT1 = averageItemCountT1 - characterMaster.inventory.GetTotalItemCountOfTier(ItemTier.Tier1); int itemCountT2 = averageItemCountT2 - characterMaster.inventory.GetTotalItemCountOfTier(ItemTier.Tier2); int itemCountT3 = averageItemCountT3 - characterMaster.inventory.GetTotalItemCountOfTier(ItemTier.Tier3); int itemCountTL = averageItemCountTL - characterMaster.inventory.GetTotalItemCountOfTier(ItemTier.Lunar); // int itemCountTB = averageItemCountTL - characterMaster.inventory.GetTotalItemCountOfTier(ItemTier.Boss); itemCountT1 = itemCountT1 < 0 ? 0 : itemCountT1; itemCountT2 = itemCountT2 < 0 ? 0 : itemCountT2; itemCountT3 = itemCountT3 < 0 ? 0 : itemCountT3; itemCountTL = itemCountTL < 0 ? 0 : itemCountTL; // itemCountTB = itemCountTB < 0 ? 0 : itemCountTB; /* * if (GiveExactItems.Value) * { * characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.tier1ItemList), itemCountT1); * characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.tier2ItemList), itemCountT2); * if (GiveRedItems.Value) * { * characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.tier3ItemList), itemCountT3); * } * if (GiveLunarItems.Value) * { * characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.lunarItemList), itemCountTL); * } * } */ Debug.Log(itemCountT1 + " " + itemCountT2 + " " + itemCountT3 + " itemcount to add"); Debug.Log(averageItemCountT1 + " " + averageItemCountT2 + " " + averageItemCountT3 + " average"); for (int i = 0; i < itemCountT1; i++) { characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.tier1ItemList), 1); } for (int i = 0; i < itemCountT2; i++) { characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.tier2ItemList), 1); } if (GiveRedItems.Value) { for (int i = 0; i < itemCountT3; i++) { characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.tier3ItemList), 1); } } if (GiveLunarItems.Value) { for (int i = 0; i < itemCountTL; i++) { characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.lunarItemList), 1); } } /* * if (GiveBossItems.Value) * { * for (int i = 0; i < itemCountTB; i++) * { * characterMaster.inventory.GiveItem(GetRandomItem(bossitemList), 1); * } * } */ }
private void GiveItems(On.RoR2.Run.orig_SetupUserCharacterMaster orig, Run self, NetworkUser user) { orig(self, user); if (!StartWithItems.Value || !Run.instance || Run.instance.fixedTime < 5f) { return; } //the way i did this is confusing so i'm just gonna explain these int names /* * averageItemCountT1 = average item count tier 1 * averageItemCountT2 = average item count tier 2 * averageItemCountT3 = average item count tier 3 * averageItemCountTL = average item count tier lunar * averageItemCountTB = average item count tier boss */ int averageItemCountT1 = 0; int averageItemCountT2 = 0; int averageItemCountT3 = 0; int averageItemCountTL = 0; // int averageItemCountTB = 0; ReadOnlyCollection <NetworkUser> readOnlyInstancesList = NetworkUser.readOnlyInstancesList; int playerCount = PlayerCharacterMasterController.instances.Count; if (playerCount <= 1) { return; } else { playerCount--; } for (int i = 0; i < readOnlyInstancesList.Count; i++) { if (readOnlyInstancesList[i].id.Equals(user.id)) { continue; } CharacterMaster cm = readOnlyInstancesList[i].master; averageItemCountT1 += cm.inventory.GetTotalItemCountOfTier(ItemTier.Tier1); averageItemCountT2 += cm.inventory.GetTotalItemCountOfTier(ItemTier.Tier2); averageItemCountT3 += cm.inventory.GetTotalItemCountOfTier(ItemTier.Tier3); averageItemCountTL += cm.inventory.GetTotalItemCountOfTier(ItemTier.Lunar); // averageItemCountTB += cm.inventory.GetTotalItemCountOfTier(ItemTier.Boss); } averageItemCountT1 /= playerCount; averageItemCountT2 /= playerCount; averageItemCountT3 /= playerCount; averageItemCountTL /= playerCount; // averageItemCountTB /= playerCount; CharacterMaster characterMaster = user.master; int itemCountT1 = averageItemCountT1 - characterMaster.inventory.GetTotalItemCountOfTier(ItemTier.Tier1); int itemCountT2 = averageItemCountT2 - characterMaster.inventory.GetTotalItemCountOfTier(ItemTier.Tier2); int itemCountT3 = averageItemCountT3 - characterMaster.inventory.GetTotalItemCountOfTier(ItemTier.Tier3); int itemCountTL = averageItemCountTL - characterMaster.inventory.GetTotalItemCountOfTier(ItemTier.Lunar); itemCountT1 = itemCountT1 < 0 ? 0 : itemCountT1; itemCountT2 = itemCountT2 < 0 ? 0 : itemCountT2; itemCountT3 = itemCountT3 < 0 ? 0 : itemCountT3; itemCountTL = itemCountTL < 0 ? 0 : itemCountTL; for (int i = 0; i < itemCountT1; i++) { characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.tier1ItemList), 1); } for (int i = 0; i < itemCountT2; i++) { characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.tier2ItemList), 1); } if (GiveRedItems.Value) { for (int i = 0; i < itemCountT3; i++) { characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.tier3ItemList), 1); } } if (GiveLunarItems.Value) { for (int i = 0; i < itemCountTL; i++) { characterMaster.inventory.GiveItem(GetRandomItem(ItemCatalog.lunarItemList), 1); } } }