Add exception handler, also fix scene loading when some list is null

This commit is contained in:
xeon 2024-01-25 16:28:53 +03:00
parent 7cf3c3d942
commit ce12bde5ae
3 changed files with 37 additions and 21 deletions

View file

@ -16,14 +16,14 @@ public class LevelGroupInfo
public LevelSaveType SaveType { get; set; } // 0x40
public uint CheckClearMainMissionID { get; set; } // 0x44
public uint UnlockMainMissionID { get; set; } // 0x48
public LevelAnchorInfo[] AnchorList { get; set; } = []; // 0x50
public LevelAnchorInfo[]? AnchorList { get; set; } = []; // 0x50
// TODO: public LevelModelInfo[] ModelList { get; set; } // 0x58
public LevelMonsterInfo[] MonsterList { get; set; } = []; // 0x60
public LevelPropInfo[] PropList { get; set; } = []; // 0x68
public LevelMonsterInfo[]? MonsterList { get; set; } = []; // 0x60
public LevelPropInfo[]? PropList { get; set; } = []; // 0x68
// TODO: public LevelWaypointInfo[] WaypointList { get; set; } // 0x70
// TODO: public LevelPathwayInfo[] PathwayList { get; set; } // 0x78
// TODO: public LevelBattleAreaInfo[] BattleAreaList { get; set; } // 0x80
public LevelNPCInfo[] NPCList { get; set; } = []; // 0x88
public LevelNPCInfo[]? NPCList { get; set; } = []; // 0x88
public uint GroupRefreshID { get; set; } // 0x90
// TODO: public RandomNPCMonsterInfo[] RandomNPCMonsterList { get; set; } // 0x98
public uint[] InitialRandomNPCMonsterIDList { get; set; } = []; // 0xA0

View file

@ -25,9 +25,16 @@ public abstract class ServiceCommandHandler
public async Task HandleAsync(ServiceCommand command)
{
if (_handlers.TryGetValue(command.CommandType, out HandlerDelegate? handler))
{
try
{
await handler(command);
}
catch (Exception handlingException)
{
_logger.LogError("Exception occurred while handling ServiceCommand of type {type}, trace:\n{exception}", command.CommandType, handlingException);
}
}
else
{
_logger.LogWarning("Handler for service command of type {type} not found!", command.CommandType);

View file

@ -123,6 +123,8 @@ internal class MazeManager
LevelGroupInfo? levelGroup = _levelTables.GetGroupInfo(groupInstanceInfo.GroupGUID);
if (levelGroup == null) continue;
if (levelGroup.MonsterList != null)
{
foreach (LevelMonsterInfo levelMonster in levelGroup.MonsterList)
{
if (!levelMonster.CreateOnInitial) continue;
@ -132,7 +134,10 @@ internal class MazeManager
EntityManager.AddEntity(monsterEntity);
}
}
if (levelGroup.PropList != null)
{
foreach (LevelPropInfo levelProp in levelGroup.PropList)
{
if (!levelProp.CreateOnInitial) continue;
@ -142,7 +147,10 @@ internal class MazeManager
EntityManager.AddEntity(propEntity);
}
}
if (levelGroup.NPCList != null)
{
foreach (LevelNPCInfo levelNPC in levelGroup.NPCList)
{
if (!levelNPC.CreateOnInitial) continue;
@ -154,6 +162,7 @@ internal class MazeManager
}
}
}
}
private void AddTeamMemberEntities()
{
@ -171,7 +180,7 @@ internal class MazeManager
private MotionInfo CreateInitialAvatarMotion()
{
LevelGroupInfo startGroup = _levelTables.GetGroupInfo(_floor!.StartGroup.GroupGUID)!;
LevelAnchorInfo startAnchor = startGroup.AnchorList.First(anchor => anchor.ID == _floor.StartAnchorID);
LevelAnchorInfo startAnchor = startGroup.AnchorList!.First(anchor => anchor.ID == _floor.StartAnchorID);
return MazeUtil.CreateDefaultMotion(startAnchor);
}