muffin v7.5.11
This commit is contained in:
parent
addf2d530f
commit
3102923ce2
522 changed files with 41082 additions and 211592 deletions
21
Questionable/Questionable.LgbWorker/LevelEntry.cs
Normal file
21
Questionable/Questionable.LgbWorker/LevelEntry.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Questionable.LgbWorker;
|
||||
|
||||
internal sealed class LevelEntry
|
||||
{
|
||||
[JsonPropertyName("objectId")]
|
||||
public uint ObjectId { get; set; }
|
||||
|
||||
[JsonPropertyName("territoryId")]
|
||||
public ushort TerritoryId { get; set; }
|
||||
|
||||
[JsonPropertyName("x")]
|
||||
public float X { get; set; }
|
||||
|
||||
[JsonPropertyName("y")]
|
||||
public float Y { get; set; }
|
||||
|
||||
[JsonPropertyName("z")]
|
||||
public float Z { get; set; }
|
||||
}
|
||||
7
Questionable/Questionable.LgbWorker/LgbMessageType.cs
Normal file
7
Questionable/Questionable.LgbWorker/LgbMessageType.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
namespace Questionable.LgbWorker;
|
||||
|
||||
internal enum LgbMessageType : byte
|
||||
{
|
||||
Progress = 1,
|
||||
Final
|
||||
}
|
||||
80
Questionable/Questionable.LgbWorker/LgbWorkerFraming.cs
Normal file
80
Questionable/Questionable.LgbWorker/LgbWorkerFraming.cs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Questionable.LgbWorker;
|
||||
|
||||
internal static class LgbWorkerFraming
|
||||
{
|
||||
public static void Write(Stream stream, in LgbWorkerMessage message)
|
||||
{
|
||||
using MemoryStream memoryStream = new MemoryStream();
|
||||
using BinaryWriter binaryWriter = new BinaryWriter(memoryStream, Encoding.UTF8, leaveOpen: true);
|
||||
binaryWriter.Write((byte)message.Type);
|
||||
switch (message.Type)
|
||||
{
|
||||
case LgbMessageType.Progress:
|
||||
binaryWriter.Write(message.Done);
|
||||
binaryWriter.Write(message.Total);
|
||||
break;
|
||||
case LgbMessageType.Final:
|
||||
binaryWriter.Write(message.Success);
|
||||
binaryWriter.Write(message.DurationMs);
|
||||
binaryWriter.Write(message.Error ?? string.Empty);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("message");
|
||||
}
|
||||
binaryWriter.Flush();
|
||||
byte[] array = memoryStream.ToArray();
|
||||
Span<byte> span = stackalloc byte[4];
|
||||
BitConverter.TryWriteBytes(span, array.Length);
|
||||
stream.Write(span);
|
||||
stream.Write(array);
|
||||
}
|
||||
|
||||
public static LgbWorkerMessage Read(Stream stream)
|
||||
{
|
||||
Span<byte> span = stackalloc byte[4];
|
||||
ReadExact(stream, span);
|
||||
int num = BitConverter.ToInt32(span);
|
||||
if ((num <= 0 || num > 65536) ? true : false)
|
||||
{
|
||||
throw new InvalidDataException($"Invalid frame length: {num}");
|
||||
}
|
||||
byte[] array = new byte[num];
|
||||
ReadExact(stream, array);
|
||||
using BinaryReader binaryReader = new BinaryReader(new MemoryStream(array), Encoding.UTF8);
|
||||
LgbMessageType lgbMessageType = (LgbMessageType)binaryReader.ReadByte();
|
||||
return lgbMessageType switch
|
||||
{
|
||||
LgbMessageType.Progress => new LgbWorkerMessage
|
||||
{
|
||||
Type = lgbMessageType,
|
||||
Done = binaryReader.ReadInt32(),
|
||||
Total = binaryReader.ReadInt32()
|
||||
},
|
||||
LgbMessageType.Final => new LgbWorkerMessage
|
||||
{
|
||||
Type = lgbMessageType,
|
||||
Success = binaryReader.ReadBoolean(),
|
||||
DurationMs = binaryReader.ReadInt64(),
|
||||
Error = binaryReader.ReadString()
|
||||
},
|
||||
_ => throw new InvalidDataException($"Unknown message type: {lgbMessageType}"),
|
||||
};
|
||||
}
|
||||
|
||||
private static void ReadExact(Stream stream, Span<byte> buffer)
|
||||
{
|
||||
int num;
|
||||
for (int i = 0; i < buffer.Length; i += num)
|
||||
{
|
||||
num = stream.Read(buffer.Slice(i));
|
||||
if (num == 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Questionable/Questionable.LgbWorker/LgbWorkerManifest.cs
Normal file
42
Questionable/Questionable.LgbWorker/LgbWorkerManifest.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Questionable.LgbWorker;
|
||||
|
||||
internal sealed class LgbWorkerManifest
|
||||
{
|
||||
[JsonPropertyName("sqpackPath")]
|
||||
public string SqpackPath { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("gameVersion")]
|
||||
public string GameVersion { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("npcCachePath")]
|
||||
public string NpcCachePath { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("boundaryCachePath")]
|
||||
public string BoundaryCachePath { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("territories")]
|
||||
public List<TerritoryEntry> Territories { get; set; } = new List<TerritoryEntry>();
|
||||
|
||||
[JsonPropertyName("levelEntries")]
|
||||
public List<LevelEntry> LevelEntries { get; set; } = new List<LevelEntry>();
|
||||
|
||||
public static LgbWorkerManifest Load(string path)
|
||||
{
|
||||
using FileStream utf8Json = File.OpenRead(path);
|
||||
LgbWorkerManifest? obj = JsonSerializer.Deserialize<LgbWorkerManifest>(utf8Json) ?? throw new InvalidDataException("Manifest deserialized to null");
|
||||
if (string.IsNullOrWhiteSpace(obj.SqpackPath))
|
||||
{
|
||||
throw new InvalidDataException("SqpackPath is missing");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(obj.GameVersion))
|
||||
{
|
||||
throw new InvalidDataException("GameVersion is missing");
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
16
Questionable/Questionable.LgbWorker/LgbWorkerMessage.cs
Normal file
16
Questionable/Questionable.LgbWorker/LgbWorkerMessage.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
namespace Questionable.LgbWorker;
|
||||
|
||||
internal readonly struct LgbWorkerMessage
|
||||
{
|
||||
public LgbMessageType Type { get; init; }
|
||||
|
||||
public int Done { get; init; }
|
||||
|
||||
public int Total { get; init; }
|
||||
|
||||
public bool Success { get; init; }
|
||||
|
||||
public long DurationMs { get; init; }
|
||||
|
||||
public string? Error { get; init; }
|
||||
}
|
||||
18
Questionable/Questionable.LgbWorker/TerritoryEntry.cs
Normal file
18
Questionable/Questionable.LgbWorker/TerritoryEntry.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Questionable.LgbWorker;
|
||||
|
||||
internal sealed class TerritoryEntry
|
||||
{
|
||||
[JsonPropertyName("rowId")]
|
||||
public uint RowId { get; set; }
|
||||
|
||||
[JsonPropertyName("bgPath")]
|
||||
public string BgPath { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("intendedUse")]
|
||||
public byte IntendedUse { get; set; }
|
||||
|
||||
[JsonPropertyName("hasAetheryte")]
|
||||
public bool HasAetheryte { get; set; }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue