Skip to content

Commit b365323

Browse files
authored
Add option to stop extracting after some seconds (jo3bingham#29)
* Add option to stop extracting after some seconds * Exit on invalid timestamp * Add an artificial timestamp for converted recordings * Use unsigned value to keep track of timestamp
1 parent 566d301 commit b365323

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Apps/Extract/Program.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class Program
4040
private static string _recording;
4141
private static string _tibiaDirectory = string.Empty;
4242

43+
private static ulong _timestamp = ulong.MaxValue;
44+
4345
private static bool _convertToNewFormat = false;
4446
private static bool _extractItemData = false;
4547
private static bool _extractMapData = false;
@@ -94,6 +96,9 @@ static bool ParseArgs(string[] args)
9496
"If this parameter is not specified, and an OXR file is being used, " +
9597
"the Extract app will first try to find the equivalent client version in the ClientData folder. " +
9698
"Otherwise, it will use the default path CipSoft uses upon installation.\n");
99+
Console.WriteLine("[optional] --time=<seconds> or --timestamp=<seconds>: " +
100+
"<seconds> is the number of seconds from the start of the recording to stop extraction." +
101+
"If this is not specified, extraction will run until the end of the recording.");
97102

98103
Console.WriteLine("[optional] --loglevel=[debug,info,warning,error,disabled]: " +
99104
"Sets the log level within the API. Default: error");
@@ -137,6 +142,16 @@ static bool ParseArgs(string[] args)
137142
_tibiaDirectory = splitArg[1].Replace("\"", "");
138143
}
139144
break;
145+
case "--time":
146+
case "--timestamp":
147+
{
148+
if (!ulong.TryParse(splitArg[1], out _timestamp))
149+
{
150+
Console.WriteLine($"{splitArg[1]} is not a valid timestamp!");
151+
return false;
152+
}
153+
}
154+
break;
140155
case "--loglevel":
141156
{
142157
_logLevel = Logger.ConvertToLogLevel(splitArg[1]);
@@ -429,13 +444,30 @@ static void Main(string[] args)
429444
return true;
430445
};
431446

447+
var packetCount = 0;
448+
var startTimestamp = ulong.MinValue;
432449
while (reader.BaseStream.Position < reader.BaseStream.Length)
433450
{
434451
var packetType = PacketType.Server;
435452
if (isOxRecording)
436453
{
437454
packetType = (PacketType)reader.ReadByte();
438455
var timestamp = reader.ReadInt64();
456+
// Converted recordings lack a timestamp, so we need to make an artificial one.
457+
if (timestamp == 0)
458+
{
459+
packetCount++;
460+
timestamp = packetCount * 100;
461+
}
462+
else if (startTimestamp == ulong.MinValue)
463+
{
464+
startTimestamp = (ulong)timestamp;
465+
}
466+
var elapsed = ((ulong)timestamp - startTimestamp) / 1000;
467+
if (elapsed >= _timestamp)
468+
{
469+
break;
470+
}
439471
}
440472

441473
var size = reader.ReadUInt32();

0 commit comments

Comments
 (0)