Skip to content

Commit

Permalink
Merge branch 'drms' of github.com:/Retera/ReterasModelStudio into drms
Browse files Browse the repository at this point in the history
  • Loading branch information
Retera committed Jul 17, 2022
2 parents ecbb857 + 7e3a23c commit 89363f8
Show file tree
Hide file tree
Showing 66 changed files with 3,125 additions and 1,840 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ repositories {
mavenCentral()
}



allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
Expand All @@ -31,7 +29,7 @@ allprojects {
lwjglVersion = '2.9.3'
image4jVersion = '0.7'
rsyntaxtextareaVersion = '3.0.2'
nashornVersion = '15.2'
nashornVersion = '15.3'
}

repositories {
Expand Down
2 changes: 2 additions & 0 deletions craft3data/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceCompatibility = 1.17

sourceSets.main.java.srcDirs = [ "src/" ]


Expand Down
9 changes: 5 additions & 4 deletions craft3data/src/com/hiveworkshop/ReteraCASCUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hiveworkshop;

public class ReteraCASCUtils {
public static final boolean LOAD_OLD_131_FORMAT = false;

public static boolean arraysEquals(final byte[] a, final int aFromIndex, final int aToIndex, final byte[] b,
final int bFromIndex, final int bToIndex) {
Expand All @@ -14,7 +15,7 @@ public static boolean arraysEquals(final byte[] a, final int aFromIndex, final i
if (b == null) {
return false;
}
if ((aToIndex - aFromIndex) != (bToIndex - bFromIndex)) {
if (aToIndex - aFromIndex != bToIndex - bFromIndex) {
return false;
}
int j = bFromIndex;
Expand All @@ -29,10 +30,10 @@ public static boolean arraysEquals(final byte[] a, final int aFromIndex, final i
public static int arraysCompareUnsigned(final byte[] a, final int aFromIndex, final int aToIndex, final byte[] b,
final int bFromIndex, final int bToIndex) {
final int i = arraysMismatch(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex);
if ((i >= 0) && (i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))) {
if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex)) {
return byteCompareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
}
return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
return aToIndex - aFromIndex - (bToIndex - bFromIndex);
}

private static int byteCompareUnsigned(final byte b, final byte c) {
Expand All @@ -43,7 +44,7 @@ private static int arraysMismatch(final byte[] a, final int aFromIndex, final in
final int bFromIndex, final int bToIndex) {
final int aLength = aToIndex - aFromIndex;
final int bLength = bToIndex - bFromIndex;
for (int i = 0; (i < aLength) && (i < bLength); i++) {
for (int i = 0; i < aLength && i < bLength; i++) {
if (a[aFromIndex + i] != b[bFromIndex + i]) {
return i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public ByteBuffer readFileData(final String filePath) throws IOException {
* @param useMemoryMapping If memory mapped IO should be used to read file data.
* @throws IOException If an exception occurs while mounting.
*/
public WarcraftIIICASC(final Path installFolder, final boolean useMemoryMapping) throws IOException {
public WarcraftIIICASC(final Path installFolder, final boolean useMemoryMapping, String product) throws IOException {
final Path infoFilePath = installFolder.resolve(Info.BUILD_INFO_FILE_NAME);
buildInfo = new Info(ByteBuffer.wrap(Files.readAllBytes(infoFilePath)));

Expand All @@ -195,10 +195,13 @@ public WarcraftIIICASC(final Path installFolder, final boolean useMemoryMapping)
if (activeFiledIndex == -1) {
throw new MalformedCASCStructureException("build info contains no active field");
}
int productFieldIndex = buildInfo.getFieldIndex("Product");
int recordIndex = 0;
for (; recordIndex < recordCount; recordIndex += 1) {
if (Integer.parseInt(buildInfo.getField(recordIndex, activeFiledIndex)) == 1) {
break;
if(productFieldIndex == -1 || product == null || product.equals(buildInfo.getField(recordIndex, productFieldIndex))) {
break;
}
}
}
if (recordIndex == recordCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Arrays;
import java.util.List;

import com.hiveworkshop.ReteraCASCUtils;
import com.hiveworkshop.blizzard.casc.Key;
import com.hiveworkshop.blizzard.casc.nio.MalformedCASCStructureException;

Expand Down Expand Up @@ -155,7 +156,9 @@ private StorageReference[] getFileReferences(final int fileOffset) throws Malfor
storageBuffer.get(encodingKeyDecoder);

final int physicalSize = storageBuffer.getInt();
storageBuffer.get();
if (!ReteraCASCUtils.LOAD_OLD_131_FORMAT) {
storageBuffer.get();
}
final int actualSize = storageBuffer.getInt();

final StorageReference reference = new StorageReference(offset, size, new Key(encodingKeyDecoder),
Expand All @@ -177,7 +180,7 @@ public TVFSFile loadFile(final ByteBuffer fileBuffer) throws IOException {

// check identifier

if ((localBuffer.remaining() < IDENTIFIER.remaining())
if (localBuffer.remaining() < IDENTIFIER.remaining()
|| !localBuffer.limit(IDENTIFIER.remaining()).equals(IDENTIFIER)) {
throw new MalformedCASCStructureException("missing TVFS identifier");
}
Expand All @@ -204,20 +207,20 @@ public TVFSFile loadFile(final ByteBuffer fileBuffer) throws IOException {

pathOffset = localBuffer.getInt();
pathSize = localBuffer.getInt();
if ((Integer.toUnsignedLong(pathOffset) + Integer.toUnsignedLong(pathSize)) > localBuffer.capacity()) {
if (Integer.toUnsignedLong(pathOffset) + Integer.toUnsignedLong(pathSize) > localBuffer.capacity()) {
throw new MalformedCASCStructureException("path stream extends past end of file");
}

fileReferenceOffset = localBuffer.getInt();
fileReferenceSize = localBuffer.getInt();
if ((Integer.toUnsignedLong(fileReferenceOffset) + Integer.toUnsignedLong(fileReferenceSize)) > localBuffer
if (Integer.toUnsignedLong(fileReferenceOffset) + Integer.toUnsignedLong(fileReferenceSize) > localBuffer
.capacity()) {
throw new MalformedCASCStructureException("logical data extends past end of file");
}

cascReferenceOffset = localBuffer.getInt();
cascReferenceSize = localBuffer.getInt();
if ((Integer.toUnsignedLong(cascReferenceOffset) + Integer.toUnsignedLong(cascReferenceSize)) > localBuffer
if (Integer.toUnsignedLong(cascReferenceOffset) + Integer.toUnsignedLong(cascReferenceSize) > localBuffer
.capacity()) {
throw new MalformedCASCStructureException("storage data extends past end of file");
}
Expand All @@ -227,7 +230,7 @@ public TVFSFile loadFile(final ByteBuffer fileBuffer) throws IOException {
throw new MalformedCASCStructureException("header goes out of bounds");
}

contentsOffsetSize = Math.max(1, Integer.BYTES - (Integer.numberOfLeadingZeros(cascReferenceSize) / Byte.SIZE));
contentsOffsetSize = Math.max(1, Integer.BYTES - Integer.numberOfLeadingZeros(cascReferenceSize) / Byte.SIZE);
contentsOffsetDecoder.putInt(0, 0);

localBuffer.limit(pathOffset + pathSize);
Expand Down
26 changes: 9 additions & 17 deletions craft3data/src/com/hiveworkshop/rms/editor/render3d/NGGLDP.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public void glNormal3f(final float x, final float y, final float z) {
pushFloat(baseOffset + 4, tempVec4.x);
pushFloat(baseOffset + 5, tempVec4.y);
pushFloat(baseOffset + 6, tempVec4.z);
pushFloat(baseOffset + 7, 1);
pushFloat(baseOffset + 7, 0);
normalCount++;
}

Expand Down Expand Up @@ -391,11 +391,9 @@ public void glEnableIfNeeded(final int glEnum) {
if (glEnum == GL11.GL_TEXTURE_2D) {
textureUsed = 1;
GL13.glActiveTexture(GL13.GL_TEXTURE0);
}
else if (glEnum == GL11.GL_ALPHA_TEST) {
} else if (glEnum == GL11.GL_ALPHA_TEST) {
alphaTest = 1;
}
else if (glEnum == GL11.GL_LIGHTING) {
} else if (glEnum == GL11.GL_LIGHTING) {
lightingEnabled = 1;
}
}
Expand All @@ -409,11 +407,9 @@ public void glDisableIfNeeded(final int glEnum) {
if (glEnum == GL11.GL_TEXTURE_2D) {
textureUsed = 0;
GL13.glActiveTexture(0);
}
else if (glEnum == GL11.GL_ALPHA_TEST) {
} else if (glEnum == GL11.GL_ALPHA_TEST) {
alphaTest = 0;
}
else if (glEnum == GL11.GL_LIGHTING) {
} else if (glEnum == GL11.GL_LIGHTING) {
lightingEnabled = 0;
}
}
Expand Down Expand Up @@ -983,11 +979,9 @@ public void glEnableIfNeeded(final int glEnum) {
if (glEnum == GL11.GL_TEXTURE_2D) {
textureUsed = 1;
GL13.glActiveTexture(GL13.GL_TEXTURE0 + textureUnit);
}
else if ((glEnum == GL11.GL_ALPHA_TEST) && (textureUnit == 0)) {
} else if (glEnum == GL11.GL_ALPHA_TEST && textureUnit == 0) {
alphaTest = 1;
}
else if (glEnum == GL11.GL_LIGHTING) {
} else if (glEnum == GL11.GL_LIGHTING) {
lightingEnabled = 1;
}
}
Expand All @@ -1001,11 +995,9 @@ public void glDisableIfNeeded(final int glEnum) {
if (glEnum == GL11.GL_TEXTURE_2D) {
textureUsed = 0;
GL13.glActiveTexture(0);
}
else if ((glEnum == GL11.GL_ALPHA_TEST) && (textureUnit == 0)) {
} else if (glEnum == GL11.GL_ALPHA_TEST && textureUnit == 0) {
alphaTest = 0;
}
else if (glEnum == GL11.GL_LIGHTING) {
} else if (glEnum == GL11.GL_LIGHTING) {
lightingEnabled = 0;
}
}
Expand Down
3 changes: 2 additions & 1 deletion craft3data/src/com/hiveworkshop/wc3/casc/Cascket.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.hiveworkshop.json.JSONArray;
import com.hiveworkshop.json.JSONObject;
import com.hiveworkshop.json.JSONTokener;
import com.hiveworkshop.wc3.gui.datachooser.CascDataSource;
import com.hiveworkshop.wc3.mpq.Codebase;
import com.hiveworkshop.wc3.user.WindowsRegistry;

Expand Down Expand Up @@ -73,7 +74,7 @@ public Cascket(final String warcraft3InstallPath) {
// final var localIndexFile = Paths.get("C:\\Program Files (x86)\\StarCraft
// II\\SC2Data\\data\\0000000139.idx");
try {
warcraftIIICASC = new WarcraftIIICASC(Paths.get(warcraft3InstallPath), true);
warcraftIIICASC = new WarcraftIIICASC(Paths.get(warcraft3InstallPath), true, CascDataSource.Product.WARCRAFT_III.getKey());
rootFileSystem = warcraftIIICASC.getRootFileSystem();
listFile = rootFileSystem.enumerateFiles();
final String locale = predictLocalization();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CascDataSource implements DataSource {
private List<String> listFile;
private Map<String, String> fileAliases;

public CascDataSource(final String warcraft3InstallPath, final String[] prefixes) {
public CascDataSource(final String warcraft3InstallPath, final String[] prefixes, Product product) {
this.prefixes = prefixes;
for (int i = 0; i < (prefixes.length / 2); i++) {
final String temp = prefixes[i];
Expand All @@ -36,7 +36,7 @@ public CascDataSource(final String warcraft3InstallPath, final String[] prefixes
}

try {
warcraftIIICASC = new WarcraftIIICASC(Paths.get(warcraft3InstallPath), true);
warcraftIIICASC = new WarcraftIIICASC(Paths.get(warcraft3InstallPath), true, product.key);
rootFileSystem = warcraftIIICASC.getRootFileSystem();
listFile = rootFileSystem.enumerateFiles();
fileAliases = new HashMap<>();
Expand Down Expand Up @@ -221,4 +221,16 @@ public void close() throws IOException {
warcraftIIICASC.close();
}

public static enum Product {
WARCRAFT_III("w3"), WARCRAFT_III_PUBLIC_TEST("w3t");
private String key;

private Product(String key) {
this.key = key;
}

public String getKey() {
return key;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import com.hiveworkshop.wc3.gui.datachooser.CascDataSource.Product;

public class CascDataSourceDescriptor implements DataSourceDescriptor {
/**
Expand All @@ -11,20 +14,26 @@ public class CascDataSourceDescriptor implements DataSourceDescriptor {
private static final long serialVersionUID = 832549098549298820L;
private final String gameInstallPath;
private final List<String> prefixes;
private final CascDataSource.Product product;

public CascDataSourceDescriptor(final String gameInstallPath, final List<String> prefixes) {
public CascDataSourceDescriptor(final String gameInstallPath, final List<String> prefixes, CascDataSource.Product product) {
this.gameInstallPath = gameInstallPath;
this.prefixes = prefixes;
this.product = product;
}

@Override
public DataSource createDataSource() {
return new CascDataSource(gameInstallPath, prefixes.toArray(new String[prefixes.size()]));
CascDataSource.Product product = this.product;
if(product == null) {
product = Product.WARCRAFT_III;
}
return new CascDataSource(gameInstallPath, prefixes.toArray(new String[prefixes.size()]), product);
}

@Override
public String getDisplayName() {
return "CASC: " + gameInstallPath;
return "CASC: " + gameInstallPath + " ("+ product+")";
}

public void addPrefix(final String prefix) {
Expand Down Expand Up @@ -57,44 +66,28 @@ public List<String> getPrefixes() {

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + ((gameInstallPath == null) ? 0 : gameInstallPath.hashCode());
result = (prime * result) + ((prefixes == null) ? 0 : prefixes.hashCode());
return result;
return Objects.hash(gameInstallPath, prefixes, product);
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
public boolean equals(Object obj) {
if (this == obj)
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (obj == null)
return false;
}
final CascDataSourceDescriptor other = (CascDataSourceDescriptor) obj;
if (gameInstallPath == null) {
if (other.gameInstallPath != null) {
return false;
}
} else if (!gameInstallPath.equals(other.gameInstallPath)) {
return false;
}
if (prefixes == null) {
if (other.prefixes != null) {
return false;
}
} else if (!prefixes.equals(other.prefixes)) {
if (getClass() != obj.getClass())
return false;
}
return true;
CascDataSourceDescriptor other = (CascDataSourceDescriptor) obj;
return Objects.equals(gameInstallPath, other.gameInstallPath) && Objects.equals(prefixes, other.prefixes)
&& product == other.product;
}

@Override
public DataSourceDescriptor duplicate() {
return new CascDataSourceDescriptor(gameInstallPath, new ArrayList<>(prefixes));
return new CascDataSourceDescriptor(gameInstallPath, new ArrayList<>(prefixes), product);
}

public CascDataSource.Product getProduct() {
return product;
}
}
Loading

0 comments on commit 89363f8

Please sign in to comment.