Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions RszTool/EnumParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ public static EnumParser GetInstance(string jsonPath)

public EnumDict EnumDict { get; }

public static EnumParser FromJson(string json)
{
return new EnumParser(new EnumDict(JsonSerializer.Deserialize<Dictionary<string, EnumData>>(json) ?? []));
}

public EnumParser(EnumDict enumDict)
{
EnumDict = enumDict;
}

public EnumParser(string jsonPath)
{
if (File.Exists(jsonPath))
Expand Down
12 changes: 11 additions & 1 deletion RszTool/RszFile/PfbFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,17 @@ public GameObjectData? Parent
set => parentRef = value != null ? new(value) : null;
}

public string? Name => (Instance?.GetFieldValue("v0") ?? Instance?.GetFieldValue("Name")) as string;
public string? Name
{
get => (Instance?.GetFieldValue("v0") ?? Instance?.GetFieldValue("Name")) as string;
set
{
if (Instance != null && value != null)
{
Instance?.SetFieldValue("Name", value);
}
}
}

public int? ObjectId => Info?.Data.objectId;

Expand Down
15 changes: 1 addition & 14 deletions RszTool/RszFile/RSZFile.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text;
using RszTool.Common;

namespace RszTool
{
Expand Down Expand Up @@ -31,7 +30,7 @@ public struct ObjectTable
/// 基于InstanceInfoList生成的实例列表
/// 一般第一个项是NULL,手动构建时需要注意
/// </summary>
public List<RszInstance> InstanceList { get; } = new();
public RszInstanceList InstanceList { get; } = new();
/// <summary>
/// 基于ObjectTableList生成的实例列表,是对外公开的实例,
/// InstanceList中包括里面依赖的成员实例或者实例数组的项
Expand Down Expand Up @@ -344,25 +343,13 @@ public void InstanceUnflatten(RszInstance instance)
{
if (items[j] is int instanceId)
{
if (instanceId >= instance.Index && field.IsTypeInferred)
{
// TODO: may detect error, should roll back
field.type = RszFieldType.S32;
throw new RszRetryOpenException($"Detected {instance.RszClass.name}.{field.name} as Object before, but seems wrong");
}
items[j] = InstanceList[instanceId];
InstanceUnflatten(InstanceList[instanceId]);
}
}
}
else if (instance.Values[i] is int instanceId)
{
if (instanceId >= instance.Index && field.IsTypeInferred)
{
// TODO: may detect error, should roll back
field.type = RszFieldType.S32;
throw new RszRetryOpenException($"Detected {instance.RszClass.name}.{field.name} as Object before, but seems wrong");
}
instance.Values[i] = InstanceList[instanceId];
InstanceUnflatten(InstanceList[instanceId]);
}
Expand Down
8 changes: 8 additions & 0 deletions RszTool/RszFile/RszFileOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ public class RszFileOption
public RszParser RszParser { get; set; }
public EnumParser EnumParser { get; set; }

public RszFileOption(GameName gameName, GameVersion version, RszParser rszParser, EnumParser enumParser)
{
GameName = gameName;
Version = version;
RszParser = rszParser;
EnumParser = enumParser;
}

public RszFileOption(GameName gameName)
{
GameName = gameName;
Expand Down
1 change: 1 addition & 0 deletions RszTool/RszFile/RszInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ public static Type RszFieldTypeToCSharpType(RszFieldType type)
RszFieldType.Cone => typeof(via.Cone),
RszFieldType.Line => typeof(via.Line),
RszFieldType.LineSegment => typeof(via.LineSegment),
RszFieldType.OBB => typeof(via.OBB),
RszFieldType.Plane => typeof(via.Plane),
RszFieldType.PlaneXZ => typeof(via.PlaneXZ),
RszFieldType.Size => typeof(via.Size),
Expand Down
55 changes: 55 additions & 0 deletions RszTool/RszFile/RszInstanceList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections;

namespace RszTool
{
public class RszInstanceList : IEnumerable<RszInstance>, IList<RszInstance>
{
private readonly List<RszInstance> _list = new();
private readonly Dictionary<RszInstance, int> _indexMap = new();

public RszInstance this[int index]
{
get => _list[index];
set => throw new NotSupportedException();
}

RszInstance IList<RszInstance>.this[int index]
{
get => this[index];
set => this[index] = value;
}

public int Count => _list.Count;
public bool IsReadOnly => false;

public void Add(RszInstance item)
{
_list.Add(item);
_indexMap.Add(item, 0);
}

public void Clear()
{
_list.Clear();
_indexMap.Clear();
}

public int IndexOf(RszInstance item)
{
var result = -1;
if (_indexMap.TryGetValue(item, out var index))
result = index;
return result;
}

public bool Contains(RszInstance item) => _list.IndexOf(item) != -1;

public IEnumerator<RszInstance> GetEnumerator() => _list.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public void CopyTo(RszInstance[] array, int arrayIndex) => throw new NotImplementedException();
public void Insert(int index, RszInstance item) => throw new NotImplementedException();
public bool Remove(RszInstance item) => throw new NotImplementedException();
public void RemoveAt(int index) => throw new NotImplementedException();
}
}
12 changes: 11 additions & 1 deletion RszTool/RszFile/ScnFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,17 @@ public GameObjectData? Parent
set => parentRef = value != null ? new(value) : null;
}

public string? Name => (Instance?.GetFieldValue("v0") ?? Instance?.GetFieldValue("Name")) as string;
public string? Name
{
get => (Instance?.GetFieldValue("v0") ?? Instance?.GetFieldValue("Name")) as string;
set
{
if (Instance != null && value != null)
{
Instance?.SetFieldValue("Name", value);
}
}
}

public int? ObjectId => Info?.Data.objectId;

Expand Down
16 changes: 16 additions & 0 deletions RszTool/RszParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ public static RszParser GetInstance(string jsonPath)

public Dictionary<uint, RszClass> ClassDict => classDict;

public RszParser(IEnumerable<RszClass> classes)
{
classDict = classes.ToDictionary(x => x.typeId);
classNameDict = classes.ToDictionary(x => x.name);
foreach (var c in classes)
{
foreach (var field in c.fields)
{
if (field.type == RszFieldType.Data)
{
field.GuessDataType();
}
}
}
}

public RszParser(string jsonPath)
{
classDict = new();
Expand Down
2 changes: 1 addition & 1 deletion RszTool/RszTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>

Expand Down