Skip to content

Commit e5ffc6b

Browse files
authored
Fix objmod data pointer issue (#1135)
1 parent 275d814 commit e5ffc6b

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/intermediateLang/interpreter/CompiletimeNatives.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private void modifyObject(ObjMod.Obj od, ILconstString modification, ObjMod.ValT
137137
for (ObjMod.Obj.Mod m : od.getMods()) {
138138
if (m instanceof ObjMod.Obj.ExtendedMod) {
139139
ObjMod.Obj.ExtendedMod extMod = (ObjMod.Obj.ExtendedMod) m;
140-
if (extMod.getId().getVal().equals(modificationId) && extMod.getLevel() == level) {
140+
if (extMod.getId().getVal().equals(modificationId) && extMod.getLevel() == level && extMod.getDataPt() == datapointer) {
141141
// How to set data???
142142
foundMod = extMod;
143143
break;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package tests.wurstscript.tests;
2+
3+
import de.peeeq.wurstio.intermediateLang.interpreter.CompiletimeNatives;
4+
import de.peeeq.wurstscript.intermediatelang.ILconstString;
5+
import net.moonlightflower.wc3libs.bin.ObjMod;
6+
import net.moonlightflower.wc3libs.bin.app.objMod.W3A;
7+
import net.moonlightflower.wc3libs.dataTypes.DataType;
8+
import net.moonlightflower.wc3libs.dataTypes.app.War3Real;
9+
import net.moonlightflower.wc3libs.misc.MetaFieldId;
10+
import net.moonlightflower.wc3libs.misc.ObjId;
11+
import org.testng.annotations.Test;
12+
13+
import java.lang.reflect.Method;
14+
import java.util.List;
15+
import java.util.Set;
16+
import java.util.stream.Collectors;
17+
18+
import static org.testng.Assert.assertEquals;
19+
import static org.testng.Assert.assertTrue;
20+
21+
public class CompiletimeNativesTest {
22+
23+
@Test
24+
public void modifyObjectKeepsDifferentDataPointers() throws Exception {
25+
CompiletimeNatives natives = new CompiletimeNatives(null, null, false);
26+
W3A w3a = new W3A();
27+
W3A.Obj obj = w3a.addObj(ObjId.valueOf("A001"), ObjId.valueOf("Abas"));
28+
29+
Method modifyObject = CompiletimeNatives.class.getDeclaredMethod(
30+
"modifyObject",
31+
ObjMod.Obj.class,
32+
ILconstString.class,
33+
ObjMod.ValType.class,
34+
int.class,
35+
int.class,
36+
DataType.class);
37+
modifyObject.setAccessible(true);
38+
39+
MetaFieldId unrealId = MetaFieldId.valueOf("unat");
40+
modifyObject.invoke(natives, obj, new ILconstString(unrealId.getVal()), ObjMod.ValType.UNREAL, 1, 0, War3Real.valueOf(1.0));
41+
modifyObject.invoke(natives, obj, new ILconstString(unrealId.getVal()), ObjMod.ValType.UNREAL, 1, 1, War3Real.valueOf(2.0));
42+
43+
List<ObjMod.Obj.ExtendedMod> unrealMods = obj.getMods().stream()
44+
.filter(m -> m instanceof ObjMod.Obj.ExtendedMod)
45+
.map(m -> (ObjMod.Obj.ExtendedMod) m)
46+
.filter(m -> unrealId.equals(m.getId()) && m.getLevel() == 1)
47+
.collect(Collectors.toList());
48+
49+
assertEquals(unrealMods.size(), 2, "Mods with distinct data pointers should both be kept");
50+
Set<Integer> dataPointers = unrealMods.stream()
51+
.map(ObjMod.Obj.ExtendedMod::getDataPt)
52+
.collect(Collectors.toSet());
53+
assertTrue(dataPointers.contains(0));
54+
assertTrue(dataPointers.contains(1));
55+
}
56+
}

0 commit comments

Comments
 (0)