Stubbed out D2SReader#copyTo(D2S,CharData)

This commit is contained in:
Collin Smith 2020-08-17 20:31:28 -07:00
parent daaf6773c2
commit 447fc70ad2
2 changed files with 47 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package com.riiablo.save.d2s;
import io.netty.util.ByteProcessor;
import org.apache.logging.log4j.Logger;
import com.riiablo.io.ByteInput;
@ -8,12 +9,30 @@ import com.riiablo.io.UnsafeNarrowing;
import com.riiablo.item.ItemReader;
import com.riiablo.log.Log;
import com.riiablo.log.LogManager;
import com.riiablo.save.CharData;
public enum D2SReader {
INSTANCE;
private static final Logger log = LogManager.getLogger(D2SReader.class);
// set the value of it in the d2s data to be zero and iterate through all the bytes
public int calculateChecksum(ByteInput in) {
ChecksumCalculator checksumCalculator = new ChecksumCalculator();
in.buffer().forEachByte(checksumCalculator);
return checksumCalculator.checksum;
}
private static class ChecksumCalculator implements ByteProcessor {
int checksum = 0;
@Override
public boolean process(byte value) {
checksum = (checksum << 1) + value;
return true;
}
}
public D2S readD2S(ByteInput in) {
log.trace("Reading d2s...");
log.trace("Validating d2s signature");
@ -59,10 +78,29 @@ public enum D2SReader {
case D2S.VERSION_109:
default:
log.error("Unsupported d2s version: " + D2S.getVersionString(d2s.version));
return d2s;
}
} finally {
Log.remove("d2s.version");
}
}
CharData copyTo(D2S d2s, CharData data) {
try {
Log.put("d2s.version", d2s.version);
switch (d2s.version) {
case D2S.VERSION_110:
return D2SReader96.copyTo(d2s, data);
case D2S.VERSION_100:
case D2S.VERSION_107:
case D2S.VERSION_108:
case D2S.VERSION_109:
default:
log.error("Unsupported d2s version: " + D2S.getVersionString(d2s.version));
return data;
}
} finally {
Log.remove("d2s.version");
}
return d2s;
}
}

View File

@ -19,6 +19,7 @@ import com.riiablo.item.ItemReader;
import com.riiablo.item.Stat;
import com.riiablo.log.Log;
import com.riiablo.log.LogManager;
import com.riiablo.save.CharData;
import com.riiablo.util.DebugUtils;
public class D2SReader96 {
@ -441,4 +442,11 @@ public class D2SReader96 {
}
return golem;
}
static CharData copyTo(D2S d2s, CharData data) {
throw new UnsupportedOperationException();
}
// TODO: Tuples should be specific to versions -- versions may have different data types, fields, etc
// static class D2SData extends D2S {}
}