-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
147 lines (116 loc) · 4.94 KB
/
Copy pathProgram.cs
File metadata and controls
147 lines (116 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System.Buffers.Binary;
using MaterialLib;
using NResLib;
using ParkanPlayground;
// ========== ANALYZE MATERIALS 72 AND 88 FROM LANDSCAPE 0B ==========
// 1. Load Material.lib
var materialLibPath = @"E:\ParkanUnpacked\Material.lib.nres";
if (!File.Exists(materialLibPath))
{
// Try alternative path
materialLibPath = @"C:\Program Files (x86)\Nikita\Iron Strategy\DATA\Material.lib";
}
Console.WriteLine($"Loading Material.lib from: {materialLibPath}");
var matLibResult = NResParser.ReadFile(materialLibPath);
if (matLibResult.Archive is null)
{
Console.WriteLine($"ERROR loading Material.lib: {matLibResult.Error}");
Console.WriteLine("Trying to list available .lib files...");
// List what's available
var dataPath = @"C:\Program Files (x86)\Nikita\Iron Strategy\DATA";
if (Directory.Exists(dataPath))
{
foreach (var f in Directory.GetFiles(dataPath, "*.lib"))
{
Console.WriteLine($" Found: {f}");
}
}
return;
}
Console.WriteLine($"Material.lib loaded: {matLibResult.Archive.Files.Count} files\n");
// 2. Find materials by index (72 and 88)
using var matFs = new FileStream(materialLibPath, FileMode.Open, FileAccess.Read, FileShare.Read);
var targetIds = new[] { 72, 88 };
foreach (var targetId in targetIds)
{
// Material files are stored with their ID in the archive
var matEntry = matLibResult.Archive.Files.FirstOrDefault(f => f.DirectoryIndex == targetId);
if (matEntry == null)
{
Console.WriteLine($"=== Material {targetId}: NOT FOUND ===\n");
continue;
}
Console.WriteLine($"=== Material {targetId} ===");
Console.WriteLine($" DirectoryIndex: {matEntry.DirectoryIndex}");
Console.WriteLine($" SortIndex: {matEntry.SortIndex}");
Console.WriteLine($" Name: {matEntry.FileName}");
Console.WriteLine($" ElementCount (Version): {matEntry.ElementCount}");
Console.WriteLine($" ElementSize (Magic1): {matEntry.ElementSize}");
Console.WriteLine($" Offset: {matEntry.OffsetInFile}");
Console.WriteLine($" Data size: {matEntry.ElementCount * matEntry.ElementSize} bytes");
// Parse the material
matFs.Seek(matEntry.OffsetInFile, SeekOrigin.Begin);
try
{
var material = MaterialParser.ReadFromStream(
matFs,
matEntry.FileName ?? $"MAT_{targetId}",
matEntry.ElementCount,
matEntry.ElementSize);
Console.WriteLine($"\n Parsed Material:");
Console.WriteLine($" Rendering Type: {material.MaterialRenderingType}");
Console.WriteLine($" Supports Bump: {material.SupportsBumpMapping}");
Console.WriteLine($" Source Blend: {material.SourceBlendMode}");
Console.WriteLine($" Dest Blend: {material.DestBlendMode}");
Console.WriteLine($" Stages: {material.Stages.Count}");
Console.WriteLine($" Animations: {material.Animations.Count}");
for (int i = 0; i < material.Stages.Count; i++)
{
var stage = material.Stages[i];
Console.WriteLine($"\n Stage {i}:");
Console.WriteLine($" Texture: \"{stage.TextureName}\"");
Console.WriteLine($" TextureStageIndex: {stage.TextureStageIndex}");
Console.WriteLine($" Diffuse: ({stage.DiffuseR:F2}, {stage.DiffuseG:F2}, {stage.DiffuseB:F2}, {stage.DiffuseA:F2})");
Console.WriteLine($" Ambient: ({stage.AmbientR:F2}, {stage.AmbientG:F2}, {stage.AmbientB:F2}, {stage.AmbientA:F2})");
}
}
catch (Exception ex)
{
Console.WriteLine($" ERROR parsing: {ex.Message}");
}
Console.WriteLine();
}
// 3. Also show .wea file contents for context
Console.WriteLine("=== WEA FILES (landscape materials) ===");
var weaPath1 = @"C:\Program Files (x86)\Nikita\Iron Strategy\DATA\MAPS\SC_1\Land1.wea";
var weaPath2 = @"C:\Program Files (x86)\Nikita\Iron Strategy\DATA\MAPS\SC_1\Land2.wea";
if (File.Exists(weaPath1))
{
Console.WriteLine($"\nLand1.wea:");
foreach (var line in File.ReadAllLines(weaPath1))
Console.WriteLine($" {line}");
}
if (File.Exists(weaPath2))
{
Console.WriteLine($"\nLand2.wea:");
foreach (var line in File.ReadAllLines(weaPath2))
Console.WriteLine($" {line}");
}
// 4. Find materials referenced in .wea by name
Console.WriteLine("\n=== MATERIALS REFERENCED IN WEA ===");
var weaMatNames = new[] { "B_S0", "L04", "L02", "L00", "DEFAULT", "L05", "L03", "L01" };
foreach (var name in weaMatNames)
{
var searchName = $"MAT0_{name}";
var found = matLibResult.Archive.Files
.FirstOrDefault(f => f.FileName?.Contains(searchName, StringComparison.OrdinalIgnoreCase) == true);
if (found != null)
{
Console.WriteLine($" {name,-10} -> DirectoryIndex {found.DirectoryIndex,3}, SortIndex {found.SortIndex,3}: {found.FileName}");
}
else
{
Console.WriteLine($" {name,-10} -> NOT FOUND");
}
}
Console.WriteLine("\nDone!");