Renamed readUnsigned31OrLess to readU31

This commit is contained in:
Collin Smith 2020-08-03 16:04:46 -07:00
parent 10f8945ddb
commit 8c9d51ee03
4 changed files with 37 additions and 37 deletions

View File

@ -145,7 +145,7 @@ public class BitStream {
return (short) readUnsigned(bits);
}
public int readUnsigned31OrLess(int bits) {
public int readU31(int bits) {
assert bits < Integer.SIZE : "only 31 bits can fit into int and be unsigned. bits: " + bits;
return (int) readUnsigned(bits);
}

View File

@ -130,7 +130,7 @@ public class ItemSerializer {
switch (item.quality) {
case LOW:
case HIGH:
item.qualityId = bitStream.readUnsigned31OrLess(3);
item.qualityId = bitStream.readU31(3);
log.trace("qualityId: {}", item.qualityId);
return true;
@ -139,7 +139,7 @@ public class ItemSerializer {
return true;
case SET:
item.qualityId = bitStream.readUnsigned31OrLess(Item.SET_ID_SIZE);
item.qualityId = bitStream.readU31(Item.SET_ID_SIZE);
log.trace("qualityId: {}", item.qualityId);
item.qualityData = Riiablo.files.SetItems.get(item.qualityId);
log.trace("qualityData: {}", item.qualityData);
@ -151,7 +151,7 @@ public class ItemSerializer {
return true;
case UNIQUE:
item.qualityId = bitStream.readUnsigned31OrLess(Item.UNIQUE_ID_SIZE);
item.qualityId = bitStream.readU31(Item.UNIQUE_ID_SIZE);
log.trace("qualityId: {}", item.qualityId);
item.qualityData = Riiablo.files.UniqueItems.get(item.qualityId);
log.trace("qualityData: {}", item.qualityData);
@ -163,13 +163,13 @@ public class ItemSerializer {
return true;
case MAGIC:
item.qualityId = bitStream.readUnsigned31OrLess(2 * Item.MAGIC_AFFIX_SIZE); // 11 for prefix, 11 for suffix
item.qualityId = bitStream.readU31(2 * Item.MAGIC_AFFIX_SIZE); // 11 for prefix, 11 for suffix
log.trace("qualityId: {}", item.qualityId);
return true;
case RARE:
case CRAFTED:
item.qualityId = bitStream.readUnsigned31OrLess(2 * Item.RARE_AFFIX_SIZE); // 8 for prefix, 8 for suffix
item.qualityId = bitStream.readU31(2 * Item.RARE_AFFIX_SIZE); // 8 for prefix, 8 for suffix
log.trace("qualityId: {}", item.qualityId);
item.qualityData = new RareQualityData(bitStream);
log.trace("qualityData: {}", item.qualityData);

View File

@ -1,9 +1,10 @@
package com.riiablo.item;
import com.google.common.primitives.UnsignedInts;
import java.util.Arrays;
import com.badlogic.gdx.Gdx;
import com.riiablo.save.CharData;
import com.riiablo.CharacterClass;
import com.riiablo.Riiablo;
import com.riiablo.codec.excel.CharStats;
@ -11,8 +12,7 @@ import com.riiablo.codec.excel.ItemStatCost;
import com.riiablo.codec.excel.SkillDesc;
import com.riiablo.codec.excel.Skills;
import com.riiablo.codec.util.BitStream;
import java.util.Arrays;
import com.riiablo.save.CharData;
@SuppressWarnings("unused")
public class Stat implements Comparable<Stat> {
@ -487,8 +487,8 @@ public class Stat implements Comparable<Stat> {
Stat _obtain(int stat, BitStream bitStream) {
this.id = stat;
entry = Riiablo.files.ItemStatCost.get(stat);
param = bitStream.readUnsigned31OrLess(entry.Save_Param_Bits);
val = bitStream.readUnsigned31OrLess(entry.Save_Bits) - entry.Save_Add;
param = bitStream.readU31(entry.Save_Param_Bits);
val = bitStream.readU31(entry.Save_Bits) - entry.Save_Add;
hash = hash(stat, param);
modified = false;
return this;

View File

@ -170,18 +170,18 @@ public class D2S {
BitStream bitStream;
for (int i = 0, i0 = Riiablo.MAX_DIFFS; i < i0; i++) {
bitStream = new BitStream(quests.data[i]);
for (int q = 0, q0 = 8; q < q0; q++) data.questData[i][0][q] = (short) bitStream.readUnsigned31OrLess(16);
for (int q = 0, q0 = 8; q < q0; q++) data.questData[i][1][q] = (short) bitStream.readUnsigned31OrLess(16);
for (int q = 0, q0 = 8; q < q0; q++) data.questData[i][2][q] = (short) bitStream.readUnsigned31OrLess(16);
for (int q = 0, q0 = 8; q < q0; q++) data.questData[i][3][q] = (short) bitStream.readUnsigned31OrLess(16);
for (int q = 0, q0 = 8; q < q0; q++) data.questData[i][4][q] = (short) bitStream.readUnsigned31OrLess(16);
for (int q = 0, q0 = 8; q < q0; q++) data.questData[i][0][q] = (short) bitStream.readU31(16);
for (int q = 0, q0 = 8; q < q0; q++) data.questData[i][1][q] = (short) bitStream.readU31(16);
for (int q = 0, q0 = 8; q < q0; q++) data.questData[i][2][q] = (short) bitStream.readU31(16);
for (int q = 0, q0 = 8; q < q0; q++) data.questData[i][3][q] = (short) bitStream.readU31(16);
for (int q = 0, q0 = 8; q < q0; q++) data.questData[i][4][q] = (short) bitStream.readU31(16);
bitStream = new BitStream(waypoints.diff[i].data);
data.waypointData[i][0] = bitStream.readUnsigned31OrLess(9);
data.waypointData[i][1] = bitStream.readUnsigned31OrLess(9);
data.waypointData[i][2] = bitStream.readUnsigned31OrLess(9);
data.waypointData[i][3] = bitStream.readUnsigned31OrLess(3);
data.waypointData[i][4] = bitStream.readUnsigned31OrLess(9);
data.waypointData[i][0] = bitStream.readU31(9);
data.waypointData[i][1] = bitStream.readU31(9);
data.waypointData[i][2] = bitStream.readU31(9);
data.waypointData[i][3] = bitStream.readU31(3);
data.waypointData[i][4] = bitStream.readU31(9);
bitStream = new BitStream(npcs.data[NPCData.GREETING_INTRO][i]);
data.npcIntroData[i] = bitStream.readUnsigned(64);
@ -655,23 +655,23 @@ public class D2S {
byte[] bytes = BufferUtils.readRemaining(slice);
BitStream bitStream = new BitStream(bytes);
for (int id; bitStream.sizeInBits() - bitStream.bitPositionInBuffer() >= 9;) {
switch (id = bitStream.readUnsigned31OrLess(9)) {
case 0x0: strength = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0x1: energy = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0x2: dexterity = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0x3: vitality = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0x4: statpts = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0x5: newskills = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0x6: hitpoints = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0x7: maxhp = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0x8: mana = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0x9: maxmana = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0xA: stamina = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0xB: maxstamina = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0xC: level = bitStream.readUnsigned31OrLess(numBits(id)); break;
switch (id = bitStream.readU31(9)) {
case 0x0: strength = bitStream.readU31(numBits(id)); break;
case 0x1: energy = bitStream.readU31(numBits(id)); break;
case 0x2: dexterity = bitStream.readU31(numBits(id)); break;
case 0x3: vitality = bitStream.readU31(numBits(id)); break;
case 0x4: statpts = bitStream.readU31(numBits(id)); break;
case 0x5: newskills = bitStream.readU31(numBits(id)); break;
case 0x6: hitpoints = bitStream.readU31(numBits(id)); break;
case 0x7: maxhp = bitStream.readU31(numBits(id)); break;
case 0x8: mana = bitStream.readU31(numBits(id)); break;
case 0x9: maxmana = bitStream.readU31(numBits(id)); break;
case 0xA: stamina = bitStream.readU31(numBits(id)); break;
case 0xB: maxstamina = bitStream.readU31(numBits(id)); break;
case 0xC: level = bitStream.readU31(numBits(id)); break;
case 0xD: experience = bitStream.readUnsigned(numBits(id)); break;
case 0xE: gold = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0xF: goldbank = bitStream.readUnsigned31OrLess(numBits(id)); break;
case 0xE: gold = bitStream.readU31(numBits(id)); break;
case 0xF: goldbank = bitStream.readU31(numBits(id)); break;
default: continue;
}
}