Permalink
Browse files

Fix the crashes when loading a map or creating a new character

  • Loading branch information...
Silv3rPRO committed Nov 18, 2018
1 parent 98c907b commit 0d49c9d5c5bf3cb12bddc31fb73e33290f9dc7f8
Showing with 41 additions and 25 deletions.
  1. +7 −0 PROBot/BotClient.cs
  2. +23 −25 PROProtocol/GameClient.cs
  3. +4 −0 PROShine/Views/ChatView.xaml.cs
  4. +7 −0 PROShine/Views/MainWindow.xaml.cs
@@ -195,6 +195,13 @@ public void Update()
return;
}

if (Game.IsCreatingNewCharacter)
{
LogMessage("Creating a new character with a random skin...");
Game.CreateCharacter(Rand.Next(14), Rand.Next(28), Rand.Next(8), Rand.Next(6), Rand.Next(5));
return;
}

if (PokemonEvolver.Update()) return;
if (MoveTeacher.Update()) return;

@@ -61,6 +61,8 @@ public class GameClient
public bool IsPCBoxRefreshing { get; private set; }
public int CurrentPCBoxId { get; private set; }

public bool IsCreatingNewCharacter { get; private set; }

public event Action ConnectionOpened;
public event Action<Exception> ConnectionFailed;
public event Action<Exception> ConnectionClosed;
@@ -146,7 +148,8 @@ public void ClearPath()
&& !_fishingTimeout.IsActive
&& !_refreshingPCBox.IsActive
&& !_npcBattleTimeout.IsActive
&& !_moveRelearnerTimeout.IsActive;
&& !_moveRelearnerTimeout.IsActive
&& !IsCreatingNewCharacter;

public bool IsTeleporting => _teleportationTimeout.IsActive;

@@ -418,12 +421,6 @@ private void UpdateScript()
SendDialogResponse(GetNextDialogResponse());
_dialogTimeout.Set();
}
else if (ScriptStatus == 1234) // Yes, this is a magic value. I don't care.
{
SendCreateCharacter(Rand.Next(14), Rand.Next(28), Rand.Next(8), Rand.Next(6), Rand.Next(5));
IsScriptActive = false;
_dialogTimeout.Set();
}
}
}

@@ -497,7 +494,15 @@ public void SendIgnoreToggle(string nickname)
SendMessage("/ignore " + nickname);
}

public void SendCreateCharacter(int hair, int colour, int tone, int clothe, int eyes)
public void CreateCharacter(int hair, int colour, int tone, int clothe, int eyes)
{
if (!IsCreatingNewCharacter) return;
IsCreatingNewCharacter = false;
SendCreateCharacter(hair, colour, tone, clothe, eyes);
_dialogTimeout.Set();
}

private void SendCreateCharacter(int hair, int colour, int tone, int clothe, int eyes)
{
SendMessage("/setchar " + hair + "," + colour + "," + tone + "," + clothe + "," + eyes);
}
@@ -995,7 +1000,10 @@ private void MapClient_ConnectionOpened()
#if DEBUG
Console.WriteLine("[+++] Connecting to the game server");
#endif
FinishLogin();
if (MapName != null && Map == null)
{
_mapClient.DownloadMap(MapName);
}
}

private void MapClient_ConnectionFailed(Exception ex)
@@ -1228,36 +1236,22 @@ private void ProcessPacket(string packet)
break;
}
}

private bool _isNewCharacter = false;

private void OnLoggedIn(string[] data)
{
Console.WriteLine("[Login] Authenticated successfully, connecting to map server");

_isNewCharacter = data[1] == "1";
IsCreatingNewCharacter = data[1] == "1";

string[] mapServerHost = data[2].Split(':');
_mapClient.Open(mapServerHost[0], int.Parse(mapServerHost[1]));
}

private void FinishLogin()
{
Console.WriteLine("[Login] Finishing the login process");

// DSSock.ProcessCommands
SendPacket(")");
SendPacket("_");
SendPacket("g");
IsAuthenticated = true;

if (_isNewCharacter)
{
IsScriptActive = true;
ScriptStatus = 1234;
_dialogTimeout.Set(Rand.Next(4000, 8000));
}

LoggedIn?.Invoke();
}

@@ -2032,8 +2026,12 @@ private void DownloadMap(string mapName)
Map = null;
AreNpcReceived = false;
MapName = mapName;
_mapClient.DownloadMap(MapName);
Players.Clear();

if (_mapClient.IsConnected)
{
_mapClient.DownloadMap(MapName);
}
}
}
}
@@ -47,6 +47,10 @@ public void Client_RefreshChannelList()
IList<ChatChannel> channelList;
lock (_bot)
{
if (_bot.Game == null)
{
return;
}
channelList = _bot.Game.Channels.ToArray();
}
foreach (ChatChannel channel in channelList)
@@ -498,6 +498,13 @@ private void Client_LoggedIn()
{
_lastQueueBreakPoint = null;
LogMessage("Authenticated successfully!");
lock (Bot)
{
if (Bot.Game != null && Bot.Game.IsCreatingNewCharacter)
{
LogMessage("This is a new account, with no character. A random character will be created if you start the bot.");
}
}
UpdateBotMenu();
StatusText.Text = "Online";
StatusText.Foreground = Brushes.DarkGreen;

0 comments on commit 0d49c9d

Please sign in to comment.