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

@ -26,7 +26,14 @@ public abstract class ServiceCommandHandler
{
if (_handlers.TryGetValue(command.CommandType, out HandlerDelegate? handler))
{
await handler(command);
try
{
await handler(command);
}
catch (Exception handlingException)
{
_logger.LogError("Exception occurred while handling ServiceCommand of type {type}, trace:\n{exception}", command.CommandType, handlingException);
}
}
else
{

View file

@ -123,34 +123,43 @@ internal class MazeManager
LevelGroupInfo? levelGroup = _levelTables.GetGroupInfo(groupInstanceInfo.GroupGUID);
if (levelGroup == null) continue;
foreach (LevelMonsterInfo levelMonster in levelGroup.MonsterList)
if (levelGroup.MonsterList != null)
{
if (!levelMonster.CreateOnInitial) continue;
foreach (LevelMonsterInfo levelMonster in levelGroup.MonsterList)
{
if (!levelMonster.CreateOnInitial) continue;
NpcMonsterEntity monsterEntity = _entityFactory.CreateNpcMonsterEntity(levelMonster, groupInstanceInfo.ID);
monsterEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelMonster));
NpcMonsterEntity monsterEntity = _entityFactory.CreateNpcMonsterEntity(levelMonster, groupInstanceInfo.ID);
monsterEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelMonster));
EntityManager.AddEntity(monsterEntity);
EntityManager.AddEntity(monsterEntity);
}
}
foreach (LevelPropInfo levelProp in levelGroup.PropList)
if (levelGroup.PropList != null)
{
if (!levelProp.CreateOnInitial) continue;
foreach (LevelPropInfo levelProp in levelGroup.PropList)
{
if (!levelProp.CreateOnInitial) continue;
PropEntity propEntity = _entityFactory.CreatePropEntity(levelProp, groupInstanceInfo.ID);
propEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelProp));
PropEntity propEntity = _entityFactory.CreatePropEntity(levelProp, groupInstanceInfo.ID);
propEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelProp));
EntityManager.AddEntity(propEntity);
EntityManager.AddEntity(propEntity);
}
}
foreach (LevelNPCInfo levelNPC in levelGroup.NPCList)
if (levelGroup.NPCList != null)
{
if (!levelNPC.CreateOnInitial) continue;
foreach (LevelNPCInfo levelNPC in levelGroup.NPCList)
{
if (!levelNPC.CreateOnInitial) continue;
NpcEntity npcEntity = _entityFactory.CreateNpcEntity(levelNPC, groupInstanceInfo.ID);
npcEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelNPC));
NpcEntity npcEntity = _entityFactory.CreateNpcEntity(levelNPC, groupInstanceInfo.ID);
npcEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelNPC));
EntityManager.AddEntity(npcEntity);
EntityManager.AddEntity(npcEntity);
}
}
}
}
@ -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);
}