Skip to content

Commit

Permalink
Drop typecodes in .dat parser that haven't been observed in practice
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Nov 28, 2021
1 parent 4efa528 commit 94fa6c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
28 changes: 7 additions & 21 deletions MCGalaxy/Levels/IO/Importers/DatImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,14 @@ class JArray {
}
}

static object ReadContent(DatReader r, byte typeCode) {
if (typeCode == TC_BLOCKDATA) {
return r.ReadBytes(r.ReadUInt8());
} else if (typeCode == TC_BLOCKDATALONG) {
return r.ReadBytes(r.ReadInt32());
} else {
return ReadObject(r, typeCode);
}
}

static object ReadObject(DatReader r) { return ReadObject(r, r.ReadUInt8()); }
static object ReadObject(DatReader r, byte typeCode) {
switch (typeCode) {
case TC_STRING: return NewString(r);
case TC_RESET: r.handles.Clear(); return null;
case TC_NULL: return null;
case TC_REFERENCE: return PrevObject(r);
case TC_CLASS: return NewClass(r);
case TC_OBJECT: return NewObject(r);
case TC_ARRAY: return NewArray(r);
case TC_CLASSDESC: return NewClassDesc(r);
}
throw new InvalidDataException("Invalid typecode: " + typeCode);
}
Expand All @@ -233,12 +220,6 @@ class JArray {
throw new InvalidDataException("Invalid stream handle: " + handle);
}

static JClassDesc NewClass(DatReader r) {
JClassDesc classDesc = ClassDesc(r);
r.handles.Add(classDesc);
return classDesc;
}

static JObject NewObject(DatReader r) {
JObject obj = new JObject();
obj.Desc = ClassDesc(r);
Expand Down Expand Up @@ -360,8 +341,13 @@ class JFieldDesc {

static void SkipAnnotation(DatReader r) {
byte typeCode;
while ((typeCode = r.ReadUInt8()) != TC_ENDBLOCKDATA) {
ReadContent(r, typeCode);
while ((typeCode = r.ReadUInt8()) != TC_ENDBLOCKDATA)
{
if (typeCode == TC_BLOCKDATA) {
r.ReadBytes(r.ReadUInt8());
} else {
ReadObject(r, typeCode);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion MCGalaxy/Modules/Relay/Discord/DiscordBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ public sealed class DiscordBot : RelayBot
}


// these characters are chosen specifically to lie within the unspecified unicode range
// these characters are chosen specifically to lie within the unspecified unicode range,
// as those characters are "application defined" (EDCX = Escaped Discord Character #X)
// https://en.wikipedia.org/wiki/Private_Use_Areas
const char UNDERSCORE = '\uEDC1'; // _
const char TILDE = '\uEDC2'; // ~
Expand Down
4 changes: 2 additions & 2 deletions MCGalaxy/Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public partial class Player : Entity, IDisposable {
return;
}

if (weapon != null) weapon.Disable();
if (weapon != null) weapon.Disable();
if (chatMsg != null) chatMsg = Colors.Escape(chatMsg);
discMsg = Colors.Escape(discMsg);

Expand Down Expand Up @@ -416,7 +416,7 @@ public partial class Player : Entity, IDisposable {
internal void SetBaseTotalModified(long modified) {
long adjust = modified - TotalModified;
TotalModified = modified;
// adjustment so that SessionModified is unaffected
// adjust so that SessionModified is unaffected
startModified += adjust;
}

Expand Down

0 comments on commit 94fa6c3

Please sign in to comment.