Compare commits
3 Commits
8f13282e04
...
cb82d3706f
| Author | SHA1 | Date | |
|---|---|---|---|
| cb82d3706f | |||
| 12a207989e | |||
| 4afcaccf75 |
@@ -4,6 +4,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Riptide.Demos.Steam.PlayerHosted;
|
||||||
using static KCM.Main;
|
using static KCM.Main;
|
||||||
|
|
||||||
namespace KCM.Packets.Lobby
|
namespace KCM.Packets.Lobby
|
||||||
@@ -29,38 +30,42 @@ namespace KCM.Packets.Lobby
|
|||||||
|
|
||||||
public override void HandlePacketClient()
|
public override void HandlePacketClient()
|
||||||
{
|
{
|
||||||
float savePercent = (float)received / (float)saveSize;
|
if (chunkId == 0)
|
||||||
|
|
||||||
// Initialize saveData and chunksReceived on the first packet received
|
|
||||||
if (saveData.Length == 1)
|
|
||||||
{
|
{
|
||||||
|
Main.helper.Log("Save Transfer started! Resetting static transfer state.");
|
||||||
Main.helper.Log("Save Transfer started!");
|
|
||||||
loadingSave = true;
|
loadingSave = true;
|
||||||
|
|
||||||
ServerLobbyScript.LoadingSave.SetActive(true);
|
|
||||||
|
|
||||||
// save percentage
|
|
||||||
|
|
||||||
|
|
||||||
saveData = new byte[saveSize];
|
saveData = new byte[saveSize];
|
||||||
chunksReceived = new bool[totalChunks];
|
chunksReceived = new bool[totalChunks];
|
||||||
|
received = 0;
|
||||||
|
|
||||||
|
ServerLobbyScript.LoadingSave.SetActive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Copy the chunk data into the correct position in saveData
|
|
||||||
Array.Copy(saveDataChunk, 0, saveData, saveDataIndex, saveDataChunk.Length);
|
Array.Copy(saveDataChunk, 0, saveData, saveDataIndex, saveDataChunk.Length);
|
||||||
|
|
||||||
// Mark this chunk as received
|
|
||||||
chunksReceived[chunkId] = true;
|
chunksReceived[chunkId] = true;
|
||||||
|
|
||||||
// Seek to the next position to write to
|
|
||||||
received += chunkSize;
|
received += chunkSize;
|
||||||
|
|
||||||
|
if (saveSize > 0)
|
||||||
|
{
|
||||||
|
float savePercent = (float)received / (float)saveSize;
|
||||||
|
string receivedKB = ((float)received / 1000f).ToString("0.00");
|
||||||
|
string totalKB = ((float)saveSize / 1000f).ToString("0.00");
|
||||||
|
|
||||||
|
ServerLobbyScript.ProgressBar.fillAmount = savePercent;
|
||||||
|
ServerLobbyScript.ProgressBarText.text = (savePercent * 100).ToString("0.00") + "%";
|
||||||
|
ServerLobbyScript.ProgressText.text = $"{receivedKB} KB / {totalKB} KB";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ServerLobbyScript.ProgressBar.fillAmount = 0f;
|
||||||
|
ServerLobbyScript.ProgressBarText.text = "0.00%";
|
||||||
|
ServerLobbyScript.ProgressText.text = "0.00 KB / 0.00 KB";
|
||||||
|
}
|
||||||
|
|
||||||
ServerLobbyScript.ProgressBar.fillAmount = savePercent;
|
|
||||||
ServerLobbyScript.ProgressBarText.text = (savePercent * 100).ToString("0.00") + "%";
|
|
||||||
ServerLobbyScript.ProgressText.text = $"{((float)(received / 1000)).ToString("0.00")} KB / {((float)(saveSize / 1000)).ToString("0.00")} KB";
|
|
||||||
|
|
||||||
|
|
||||||
if (chunkId + 1 == totalChunks)
|
if (chunkId + 1 == totalChunks)
|
||||||
@@ -70,10 +75,8 @@ namespace KCM.Packets.Lobby
|
|||||||
Main.helper.Log(WhichIsNotComplete());
|
Main.helper.Log(WhichIsNotComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if all chunks have been received
|
|
||||||
if (IsTransferComplete())
|
if (IsTransferComplete())
|
||||||
{
|
{
|
||||||
// Handle completed transfer here
|
|
||||||
Main.helper.Log("Save Transfer complete!");
|
Main.helper.Log("Save Transfer complete!");
|
||||||
|
|
||||||
LoadSaveLoadHook.saveBytes = saveData;
|
LoadSaveLoadHook.saveBytes = saveData;
|
||||||
@@ -81,8 +84,9 @@ namespace KCM.Packets.Lobby
|
|||||||
|
|
||||||
LoadSave.Load();
|
LoadSave.Load();
|
||||||
|
|
||||||
|
GameState.inst.SetNewMode(GameState.inst.playingMode);
|
||||||
|
LobbyManager.loadingSave = false;
|
||||||
|
|
||||||
LoadSaveLoadHook.saveContainer.Unpack(null);
|
|
||||||
Broadcast.OnLoadedEvent.Broadcast(new OnLoadedEvent());
|
Broadcast.OnLoadedEvent.Broadcast(new OnLoadedEvent());
|
||||||
|
|
||||||
ServerLobbyScript.LoadingSave.SetActive(false);
|
ServerLobbyScript.LoadingSave.SetActive(false);
|
||||||
|
|||||||
@@ -18,38 +18,26 @@ namespace KCM.Packets.Lobby
|
|||||||
{
|
{
|
||||||
Main.helper.Log(GameState.inst.mainMenuMode.ToString());
|
Main.helper.Log(GameState.inst.mainMenuMode.ToString());
|
||||||
|
|
||||||
// Hide server lobby
|
|
||||||
Main.TransitionTo((MenuState)200);
|
Main.TransitionTo((MenuState)200);
|
||||||
|
|
||||||
// This is run when user clicks "accept" on choose your map screeen
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!LobbyManager.loadingSave)
|
SpeedControlUI.inst.SetSpeed(0);
|
||||||
{
|
|
||||||
SpeedControlUI.inst.SetSpeed(0);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
|
||||||
typeof(MainMenuMode).GetMethod("StartGame", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(GameState.inst.mainMenuMode, null);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Main.helper.Log(ex.Message.ToString());
|
|
||||||
Main.helper.Log(ex.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
SpeedControlUI.inst.SetSpeed(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
LobbyManager.loadingSave = false;
|
typeof(MainMenuMode).GetMethod("StartGame", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(GameState.inst.mainMenuMode, null);
|
||||||
GameState.inst.SetNewMode(GameState.inst.playingMode);
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Main.helper.Log(ex.Message.ToString());
|
||||||
|
Main.helper.Log(ex.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
SpeedControlUI.inst.SetSpeed(0);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Handle exception here
|
|
||||||
Main.helper.Log(ex.Message.ToString());
|
Main.helper.Log(ex.Message.ToString());
|
||||||
Main.helper.Log(ex.ToString());
|
Main.helper.Log(ex.ToString());
|
||||||
}
|
}
|
||||||
@@ -63,51 +51,12 @@ namespace KCM.Packets.Lobby
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If loading a save, just ensure the game is in the correct UI state for loading.
|
ServerLobbyScript.LoadingSave.SetActive(true);
|
||||||
// The actual game start will happen after save data is unpacked in SaveTransferPacket.HandlePacketClient().
|
|
||||||
// This prevents MainMenuMode.StartGame() from being called prematurely and causing NullReferenceExceptions.
|
|
||||||
GameState.inst.SetNewMode(GameState.inst.playingMode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void HandlePacketServer()
|
public override void HandlePacketServer()
|
||||||
{
|
{
|
||||||
//Start();
|
|
||||||
|
|
||||||
|
|
||||||
/*AIBrainsContainer.PreStartAIConfig aiConfig = new AIBrainsContainer.PreStartAIConfig();
|
|
||||||
int count = 0;
|
|
||||||
for (int i = 0; i < RivalKingdomSettingsUI.inst.rivalItems.Length; i++)
|
|
||||||
{
|
|
||||||
RivalItemUI r = RivalKingdomSettingsUI.inst.rivalItems[i];
|
|
||||||
bool flag = r.Enabled && !r.Locked;
|
|
||||||
if (flag)
|
|
||||||
{
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int idx = 0;
|
|
||||||
aiConfig.startData = new AIBrainsContainer.PreStartAIConfig.AIStartData[count];
|
|
||||||
for (int j = 0; j < RivalKingdomSettingsUI.inst.rivalItems.Length; j++)
|
|
||||||
{
|
|
||||||
RivalItemUI item = RivalKingdomSettingsUI.inst.rivalItems[j];
|
|
||||||
bool flag2 = item.Enabled && !item.Locked;
|
|
||||||
if (flag2)
|
|
||||||
{
|
|
||||||
aiConfig.startData[idx] = new AIBrainsContainer.PreStartAIConfig.AIStartData();
|
|
||||||
aiConfig.startData[idx].landmass = item.flag.landmass;
|
|
||||||
aiConfig.startData[idx].bioCode = item.bannerIdx;
|
|
||||||
aiConfig.startData[idx].personalityKey = PersonalityCollection.aiPersonalityKeys[0];
|
|
||||||
aiConfig.startData[idx].skillLevel = item.GetSkillLevel();
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AIBrainsContainer.inst.aiStartInfo = aiConfig;
|
|
||||||
bool isControllerActive = GamepadControl.inst.isControllerActive;
|
|
||||||
if (isControllerActive)
|
|
||||||
{
|
|
||||||
ConsoleCursorMenu.inst.PrepForGamepad();
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user