Skip to content

Commit

Permalink
Improve "Check for invalid opcodes" to include opcode definitions in
Browse files Browse the repository at this point in the history
effect parameters (e.g. op101, ...)

Created new specialized datatype for opcode list representation.
  • Loading branch information
Argent77 committed Jul 29, 2023
1 parent a87e07d commit 36176b1
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/org/infinity/check/EffectValidationChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.util.List;

import org.infinity.NearInfinity;
import org.infinity.datatype.EffectBitmap;
import org.infinity.datatype.EffectType;
import org.infinity.datatype.IsNumeric;
import org.infinity.resource.AbstractStruct;
import org.infinity.resource.Profile;
import org.infinity.resource.Resource;
Expand Down Expand Up @@ -53,8 +55,8 @@ protected Runnable newWorker(ResourceEntry entry) {

private void search(ResourceEntry entry, AbstractStruct struct) {
for (final StructEntry field : struct.getFlatFields()) {
if (field instanceof EffectType) {
int value = ((EffectType) field).getValue();
if (field instanceof EffectType || field instanceof EffectBitmap) {
int value = ((IsNumeric) field).getValue();
final BaseOpcode opcode = BaseOpcode.getOpcode(value);
if (opcode instanceof DefaultOpcode) {
synchronized (hitFrame) {
Expand Down
42 changes: 42 additions & 0 deletions src/org/infinity/datatype/EffectBitmap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Near Infinity - An Infinity Engine Browser and Editor
// Copyright (C) 2001 Jon Olav Hauglid
// See LICENSE.txt for license information

package org.infinity.datatype;

import java.nio.ByteBuffer;

import org.infinity.resource.effects.BaseOpcode;

/**
* Specialized {@link Bitmap} type that represents a list of available effect opcodes.
*/
public class EffectBitmap extends Bitmap {
public static final String EFFECT_FX = "Effect";

public EffectBitmap(ByteBuffer buffer, int offset, int length) {
this(buffer, offset, length, EFFECT_FX);
}

public EffectBitmap(ByteBuffer buffer, int offset, int length, String name) {
super(buffer, offset, length, name, BaseOpcode.getEffectNames());
}

public EffectBitmap(ByteBuffer buffer, int offset, int length, boolean signed) {
this(buffer, offset, length, EFFECT_FX, signed);
}

public EffectBitmap(ByteBuffer buffer, int offset, int length, String name, boolean signed) {
super(buffer, offset, length, name, BaseOpcode.getEffectNames(), signed);
}

public EffectBitmap(ByteBuffer buffer, int offset, int length, boolean signed,
boolean showAsHex) {
this(buffer, offset, length, EFFECT_FX, signed, showAsHex);
}

public EffectBitmap(ByteBuffer buffer, int offset, int length, String name, boolean signed,
boolean showAsHex) {
super(buffer, offset, length, name, BaseOpcode.getEffectNames(), signed, showAsHex);
}
}
4 changes: 2 additions & 2 deletions src/org/infinity/resource/effects/Opcode101.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import java.nio.ByteBuffer;
import java.util.List;

import org.infinity.datatype.Bitmap;
import org.infinity.datatype.Datatype;
import org.infinity.datatype.DecNumber;
import org.infinity.datatype.EffectBitmap;
import org.infinity.resource.AbstractStruct;
import org.infinity.resource.StructEntry;

Expand All @@ -30,7 +30,7 @@ public Opcode101() {
protected String makeEffectParamsGeneric(Datatype parent, ByteBuffer buffer, int offset, List<StructEntry> list,
boolean isVersion1) {
list.add(new DecNumber(buffer, offset, 4, AbstractStruct.COMMON_UNUSED));
list.add(new Bitmap(buffer, offset + 4, 4, "Effect", getEffectNames()));
list.add(new EffectBitmap(buffer, offset + 4, 4));
return null;
}
}
6 changes: 2 additions & 4 deletions src/org/infinity/resource/effects/Opcode198.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import java.nio.ByteBuffer;
import java.util.List;

import org.infinity.datatype.Bitmap;
import org.infinity.datatype.Datatype;
import org.infinity.datatype.DecNumber;
import org.infinity.datatype.EffectBitmap;
import org.infinity.resource.AbstractStruct;
import org.infinity.resource.Profile;
import org.infinity.resource.StructEntry;
Expand All @@ -18,8 +18,6 @@
* Implemention of opcode 198.
*/
public class Opcode198 extends BaseOpcode {
private static final String EFFECT_FX = "Effect";

/** Returns the opcode name for the current game variant. */
private static String getOpcodeName() {
switch (Profile.getEngine()) {
Expand All @@ -41,7 +39,7 @@ public Opcode198() {
protected String makeEffectParamsGeneric(Datatype parent, ByteBuffer buffer, int offset, List<StructEntry> list,
boolean isVersion1) {
list.add(new DecNumber(buffer, offset, 4, AbstractStruct.COMMON_UNUSED));
list.add(new Bitmap(buffer, offset + 4, 4, EFFECT_FX, getEffectNames()));
list.add(new EffectBitmap(buffer, offset + 4, 4));
return null;
}

Expand Down
6 changes: 3 additions & 3 deletions src/org/infinity/resource/effects/Opcode261.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.infinity.datatype.Bitmap;
import org.infinity.datatype.Datatype;
import org.infinity.datatype.DecNumber;
import org.infinity.datatype.EffectBitmap;
import org.infinity.resource.AbstractStruct;
import org.infinity.resource.Profile;
import org.infinity.resource.StructEntry;
Expand All @@ -20,7 +21,6 @@
public class Opcode261 extends BaseOpcode {
private static final String EFFECT_SPELL_LEVEL = "Spell level";
private static final String EFFECT_SPELL_CLASS = "Spell class";
private static final String EFFECT_FX = "Effect";

private static final String RES_TYPE_IWD2 = "SPL";

Expand Down Expand Up @@ -63,15 +63,15 @@ protected String makeEffectParamsBG1(Datatype parent, ByteBuffer buffer, int off
protected String makeEffectParamsIWD(Datatype parent, ByteBuffer buffer, int offset, List<StructEntry> list,
boolean isVersion1) {
list.add(new DecNumber(buffer, offset, 4, AbstractStruct.COMMON_UNUSED));
list.add(new Bitmap(buffer, offset + 4, 4, EFFECT_FX, getEffectNames()));
list.add(new EffectBitmap(buffer, offset + 4, 4));
return null;
}

@Override
protected String makeEffectParamsIWD2(Datatype parent, ByteBuffer buffer, int offset, List<StructEntry> list,
boolean isVersion1) {
list.add(new DecNumber(buffer, offset, 4, AbstractStruct.COMMON_UNUSED));
list.add(new Bitmap(buffer, offset + 4, 4, EFFECT_FX, getEffectNames()));
list.add(new EffectBitmap(buffer, offset + 4, 4));
return RES_TYPE_IWD2;
}

Expand Down
5 changes: 2 additions & 3 deletions src/org/infinity/resource/effects/Opcode276.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.infinity.datatype.Bitmap;
import org.infinity.datatype.Datatype;
import org.infinity.datatype.DecNumber;
import org.infinity.datatype.EffectBitmap;
import org.infinity.resource.AbstractStruct;
import org.infinity.resource.Profile;
import org.infinity.resource.StructEntry;
Expand All @@ -18,8 +19,6 @@
* Implemention of opcode 276.
*/
public class Opcode276 extends BaseOpcode {
private static final String EFFECT_FX = "Effect";

/** Returns the opcode name for the current game variant. */
private static String getOpcodeName() {
switch (Profile.getEngine()) {
Expand Down Expand Up @@ -56,7 +55,7 @@ protected String makeEffectParamsBG1(Datatype parent, ByteBuffer buffer, int off
protected String makeEffectParamsIWD(Datatype parent, ByteBuffer buffer, int offset, List<StructEntry> list,
boolean isVersion1) {
list.add(new DecNumber(buffer, offset, 4, AbstractStruct.COMMON_UNUSED));
list.add(new Bitmap(buffer, offset + 4, 4, EFFECT_FX, getEffectNames()));
list.add(new EffectBitmap(buffer, offset + 4, 4));
return null;
}

Expand Down
5 changes: 2 additions & 3 deletions src/org/infinity/resource/effects/Opcode337.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import java.nio.ByteBuffer;
import java.util.List;

import org.infinity.datatype.Bitmap;
import org.infinity.datatype.Datatype;
import org.infinity.datatype.DecNumber;
import org.infinity.datatype.EffectBitmap;
import org.infinity.resource.Profile;
import org.infinity.resource.StructEntry;

Expand All @@ -18,7 +18,6 @@
*/
public class Opcode337 extends BaseOpcode {
private static final String EFFECT_MATCH_P2_VALUE = "Match 'Parameter 2' value";
private static final String EFFECT_FX = "Effect";

/** Returns the opcode name for the current game variant. */
private static String getOpcodeName() {
Expand All @@ -38,7 +37,7 @@ public Opcode337() {
protected String makeEffectParamsEE(Datatype parent, ByteBuffer buffer, int offset, List<StructEntry> list,
boolean isVersion1) {
list.add(new DecNumber(buffer, offset, 4, EFFECT_MATCH_P2_VALUE));
list.add(new Bitmap(buffer, offset + 4, 4, EFFECT_FX, getEffectNames()));
list.add(new EffectBitmap(buffer, offset + 4, 4));
return null;
}
}

0 comments on commit 36176b1

Please sign in to comment.