Skip to content

Commit cc7a011

Browse files
authored
Merge pull request #134 from MichaelRelaxen/dl-moby-instances-model-names-or-something
More DL mission moby stuff
2 parents 113f710 + adbfc26 commit cc7a011

14 files changed

Lines changed: 754 additions & 22 deletions

File tree

LibReplanetizer/Headers/MissionHeader.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System;
99
using System.Collections.Generic;
1010
using System.IO;
11+
using System.Linq;
1112
using System.Text;
1213
using static LibReplanetizer.DataFunctions;
1314

@@ -65,6 +66,11 @@ public static List<string> FindMissionDataFiles(GameType game, string enginePath
6566

6667
return files;
6768
}
69+
public static int GetMissionId(string missionPath)
70+
{
71+
string fileName = Path.GetFileNameWithoutExtension(missionPath);
72+
return int.Parse(new string(fileName.Where(char.IsDigit).ToArray()));
73+
}
6874

6975
public byte[] Serialize()
7076
{

LibReplanetizer/Level.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,13 @@ public Level(string enginePath)
348348
}
349349
}
350350

351-
List<string> missionPaths = MissionHeader.FindMissionFiles(game, enginePath);
352351
List<string> missionDataPaths = MissionHeader.FindMissionDataFiles(game, enginePath);
353352
missions = new List<Mission>();
354353

355-
for (int i = 0; i < missionPaths.Count; i++)
354+
foreach (string datPath in missionDataPaths)
356355
{
357-
string missionPath = missionPaths[i];
356+
int missionId = MissionHeader.GetMissionId(datPath);
357+
string missionPath = Path.Join(Path.GetDirectoryName(enginePath), $"gameplay_mission_classes[{missionId}].ps3");
358358
string vramPath = missionPath.Replace(".ps3", ".vram");
359359

360360
if (!File.Exists(vramPath))
@@ -363,9 +363,7 @@ public Level(string enginePath)
363363
continue;
364364
}
365365

366-
LOGGER.Debug("Looking for mission data in {0}", missionPath);
367-
368-
Mission mission = new Mission(i);
366+
Mission mission = new Mission(missionId);
369367

370368
using (MissionParser parser = new MissionParser(game, missionPath))
371369
{
@@ -378,14 +376,8 @@ public Level(string enginePath)
378376
parser.GetTextures(mission.textures);
379377
}
380378

381-
string? datPath = missionDataPaths.FirstOrDefault(p =>
382-
Path.GetFileNameWithoutExtension(p).Contains($"[{i}]"));
383-
384-
if (datPath != null)
385-
{
386-
using var datParser = new MissionDataParser(datPath, game);
387-
mission.mobies = datParser.GetMobies(mission.models, mobyModels);
388-
}
379+
using var datParser = new MissionDataParser(datPath, game);
380+
mission.mobies = datParser.GetMobies(mission.models, mobyModels);
389381

390382
missions.Add(mission);
391383
}

Replanetizer/Frames/LevelFrame.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class LevelFrame : Frame
3737
public LevelRenderer? levelRenderer;
3838
private RendererPayload rendererPayload;
3939
private HashSet<Mission> selectedMissions = new HashSet<Mission>();
40+
public bool IsMissionActive(Mission mission) => selectedMissions.Contains(mission);
4041
public Level level { get; set; }
4142
private bool enableCameraInfo = true;
4243
public ShaderTable shaderTable;
@@ -1157,6 +1158,10 @@ private void RefreshMissionMobies()
11571158
}
11581159

11591160
activeMobies = mobies;
1161+
1162+
foreach (var frame in subFrames.OfType<ModelFrame>())
1163+
frame.UpdateModel();
1164+
11601165
InvalidateView();
11611166
}
11621167

Replanetizer/Frames/ModelFrame.cs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,25 @@ private string GetDisplayName(Model model)
202202

203203
return displayName;
204204
}
205+
private bool HasMatchingModel(List<Model> models)
206+
{
207+
if (string.IsNullOrEmpty(filter)) return false;
205208

209+
foreach (Model model in models)
210+
{
211+
string displayName = GetDisplayName(model);
212+
if (displayName.ToUpper().Contains(filterUpper))
213+
return true;
214+
}
215+
return false;
216+
}
206217
private void RenderSubTree(string name, List<Model> models, List<Texture> textureSet)
207218
{
219+
// uncollapse if we find any matching model names
220+
if (!string.IsNullOrEmpty(filter) && HasMatchingModel(models))
221+
{
222+
ImGui.SetNextItemOpen(true);
223+
}
208224
if (ImGui.TreeNode(name))
209225
{
210226
for (int i = 0; i < models.Count; i++)
@@ -236,24 +252,31 @@ private void RenderTree()
236252
RenderSubTree("Gadget", sortedGadgetModels, (level.game == GameType.RaC1) ? level.textures : level.gadgetTextures);
237253
if (level.armorModels.Count > 0)
238254
{
255+
bool hasMatch = !string.IsNullOrEmpty(filter) && level.armorModels.Exists(m =>
256+
("Armor " + level.armorModels.IndexOf(m)).ToUpper().Contains(filterUpper));
257+
258+
if (hasMatch) ImGui.SetNextItemOpen(true);
259+
239260
if (ImGui.TreeNode("Armor"))
240261
{
241262
for (int i = 0; i < level.armorModels.Count; i++)
242263
{
243-
Model armor = level.armorModels[i];
244-
RenderModelEntry(armor, level.armorTextures[i], "Armor " + i);
264+
RenderModelEntry(level.armorModels[i], level.armorTextures[i], "Armor " + i);
245265
}
246266
ImGui.TreePop();
247267
}
248268
}
269+
249270
if (sortedMissionModels.Count > 0)
250271
{
272+
bool hasMatch = !string.IsNullOrEmpty(filter) && sortedMissionModels.Exists(HasMatchingModel);
273+
if (hasMatch) ImGui.SetNextItemOpen(true);
274+
251275
if (ImGui.TreeNode("Missions"))
252276
{
253277
for (int i = 0; i < sortedMissionModels.Count; i++)
254278
{
255-
Mission mission = level.missions[i];
256-
RenderSubTree("Mission " + i, sortedMissionModels[i], mission.textures);
279+
RenderSubTree("Mission " + level.missions[i].missionID, sortedMissionModels[i], level.missions[i].textures);
257280
}
258281
ImGui.TreePop();
259282
}
@@ -289,7 +312,12 @@ private void RenderInstanceList()
289312
string objName = $"Instance##{obj.globalID}";
290313
if (obj is Moby mob)
291314
{
292-
objName = $"Instance [{GetStringFromID(mob.mobyID)}]##{mob.globalID}";
315+
objName = $"Instance [{GetStringFromID(mob.mobyID)}]";
316+
317+
if (mob.missionID != -1 && level.game == GameType.DL)
318+
{
319+
objName = $"Instance [Mission {mob.missionID}: {GetStringFromID(mob.mobyID)}]";
320+
}
293321
}
294322

295323
if (ImGui.Button(objName))
@@ -571,11 +599,20 @@ private void UpdateInstanceList()
571599
foreach (Moby mob in level.mobs)
572600
{
573601
if (mob.modelID == selectedModel.id)
574-
{
575602
selectedObjectInstances.Add(mob);
603+
}
604+
605+
foreach (var mission in level.missions)
606+
{
607+
if (!levelFrame.IsMissionActive(mission)) continue;
608+
foreach (Moby mob in mission.mobies)
609+
{
610+
if (mob.modelID == selectedModel.id)
611+
selectedObjectInstances.Add(mob);
576612
}
577613
}
578614
}
615+
579616
else if (selectedModel is TieModel)
580617
{
581618
foreach (Tie tie in level.ties)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
4+
public static class LevelLists
5+
{
6+
public static Dictionary<int, string>? GetLevelNames(string gameFile, string levelListsFolder)
7+
{
8+
string path = Path.Join(levelListsFolder, $"{gameFile}.txt");
9+
10+
if (!File.Exists(path))
11+
return null;
12+
13+
var names = new Dictionary<int, string>();
14+
15+
foreach (var line in File.ReadAllLines(path))
16+
{
17+
var parts = line.Split('=', 2);
18+
if (parts.Length == 2 && int.TryParse(parts[0].Trim(), out int id))
19+
names[id] = parts[1].Trim();
20+
}
21+
22+
return names;
23+
}
24+
25+
private static readonly Dictionary<string, string> GAME_IDS = new() {
26+
{ "NPEA00385", "RC1" },
27+
{ "NPUA80643", "RC1" },
28+
{ "NPEA00386", "RC2" },
29+
{ "NPUA80644", "RC2" },
30+
{ "NPEA00387", "RC3" },
31+
{ "NPUA80645", "RC3" },
32+
{ "NPEA00423", "RC4" },
33+
{ "NPUA80646", "RC4" },
34+
};
35+
public static string? DetectGameFile(string path)
36+
{
37+
foreach (var entry in GAME_IDS)
38+
if (path.Contains(entry.Key))
39+
return entry.Value;
40+
return null;
41+
}
42+
}

Replanetizer/LevelLists/RC1.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
0=Veldin
2+
1=Novalis
3+
2=Aridia
4+
3=Kerwan
5+
4=Eudora
6+
5=Rilgar
7+
6=Blarg
8+
7=Umbris
9+
8=Batalia
10+
9=Gaspar
11+
10=Orxon
12+
11=Pokitaru
13+
12=Hoven
14+
13=Gemlik Base
15+
14=Oltanis
16+
15=Quartu
17+
16=Kalebo III
18+
17=Drek's Fleet
19+
18=Veldin 2

Replanetizer/LevelLists/RC2.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
0=Aranos
2+
1=Oozla
3+
2=Maktar Nebula
4+
3=Endako
5+
4=Barlow
6+
5=Feltzin
7+
6=Notak
8+
7=Siberius
9+
8=Tabora
10+
9=Dobbo
11+
10=Hrugis Cloud
12+
11=Joba
13+
12=Todano
14+
13=Boldan
15+
14=Aranos 2
16+
15=Gorn
17+
16=Snivelak
18+
17=Smolg
19+
18=Damosel
20+
19=Grelbin
21+
20=Yeedil
22+
21=Insomniac Museum
23+
22=Dobbo Orbit
24+
23=Damosel Orbit
25+
24=Ship Shack
26+
25=Wupash Nebula
27+
26=Jamming Array

Replanetizer/LevelLists/RC3.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
1=Veldin
2+
2=Florana
3+
3=Starship Phoenix
4+
4=Marcadia
5+
5=Daxx
6+
6=Phoenix Rescue
7+
7=Annihilation Nation
8+
8=Aquatos
9+
9=Tyhrranosis
10+
10=Zeldrin Starport
11+
11=Obani Gemini
12+
12=Blackwater City
13+
13=Holostar Studios
14+
14=Koros
15+
16=Metropolis
16+
17=Crash Site
17+
18=Aridia
18+
19=Qwark's Hideout
19+
20=Launch Site
20+
21=Obani Draco
21+
22=Command Center
22+
23=Holostar Studios (Clank)
23+
24=Insomniac Museum
24+
26=Metropolis Rangers
25+
27=Aquatos Clank
26+
28=Aquatos Sewers
27+
29=Tyhrranosis Rangers
28+
30=Vid Comic 6
29+
31=Vid Comic 1
30+
32=Vid Comic 4
31+
33=Vid Comic 2
32+
34=Vid Comic 3
33+
35=Vid Comic 5
34+
36=Vid Comic 1 Special Edition
35+
36+
40=Bakisi Isles MP
37+
41=Hoven Gorge MP
38+
42=Outpost X12 MP
39+
43=Korgon Outpost MP
40+
44=Metropolis MP
41+
45=Blackwater City MP
42+
46=Command Center MP
43+
47=Blackwater Docks MP
44+
48=Aquatos Sewers MP
45+
49=Marcadia Palace MP
46+
50=Bakisi Isles MP (Split)
47+
51=Hoven Gorge MP (Split)
48+
52=Outpost X12 MP (Split)
49+
53=Korgon Outpost MP (Split)
50+
54=Metropolis MP (Split)
51+
55=Blackwater City MP (Split)

Replanetizer/LevelLists/RC4.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
1=Dreadzone Station
2+
2=Catacrom Four
3+
4=Sarathos
4+
5=Kronos
5+
6=Shaar
6+
7=Valix Belt
7+
8=Orxon
8+
10=Torval
9+
11=Stygia
10+
13=Maraxus
11+
14=Ghost Station
12+
15=Control Level
13+
21=Dreadzone Station (Co-Op)
14+
22=Catacrom Four (Co-Op)
15+
24=Sarathos (Co-Op)
16+
25=Kronos (Co-Op)
17+
26=Shaar (Co-Op)
18+
27=Valix Belt (Co-Op)
19+
28=Orxon (Co-Op)
20+
30=Torval (Co-Op)
21+
31=Stygia (Co-Op)
22+
33=Maraxus (Co-Op)
23+
34=Ghost Station (Co-Op)
24+
35=Control Level (Co-Op)
25+
26+
41=Battledome Tower MP
27+
42=Catacrom Graveyard MP
28+
44=Sarathos Swamp MP
29+
45=Dark Cathedral MP
30+
46=Temple of Shaar MP
31+
47=Valix Lighthouse MP
32+
48=Mining Facility MP
33+
50=Torval Ruins MP
34+
51=Tempus Station MP
35+
53=Maraxus Prison MP
36+
54=Ghost Station MP
37+
61=Battledome Tower MP (Split)
38+
62=Catacrom Graveyard MP (Split)
39+
64=Sarathos Swamp MP (Split)
40+
65=Dark Cathedral MP (Split)
41+
66=Temple of Shaar MP (Split)
42+
67=Valix Lighthouse MP (Split)
43+
68=Mining Facility MP (Split)
44+
70=Torval Ruins MP (Split)
45+
71=Tempus Station MP (Split)
46+
73=Maraxus Prison MP (Split)
47+
74=Ghost Station MP (Split)

0 commit comments

Comments
 (0)