1136 lines
58 KiB
Python
1136 lines
58 KiB
Python
import ctypes
|
|
import os
|
|
from pathlib import Path
|
|
import shlex
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed"
|
|
SOURCE = RECONSTRUCTED / "swf_draw_shape.c"
|
|
HEADER = RECONSTRUCTED / "swf_draw_shape.h"
|
|
SUPPORT = ROOT / "tests/support/swf_draw_shape_test_support.c"
|
|
VARIANTS = {
|
|
name: f"IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_{name.upper()}"
|
|
for name in ("durango", "orbis", "ps3", "vita")
|
|
}
|
|
OFFSETS = {
|
|
"durango": {"o2w": 0x468, "mode": 0x2294, "exporter": 0x2888,
|
|
"scale": 0x1F3C, "matrix": 0x1F54, "cache_max": 0x1E9C,
|
|
"cache_ratio": 0x1EB0, "frame": 0x2878,
|
|
"buffered": 0x28E0, "shape_chars": 0x28E4,
|
|
"rt_aa": 0x1F2C, "quality": 0x1E98, "rt_disabled": 0x2295,
|
|
"slice": 0x2298, "slice_bounds": 0x229C},
|
|
"orbis": {"o2w": 0x468, "mode": 0x2294, "exporter": 0x2888,
|
|
"scale": 0x1F3C, "matrix": 0x1F54, "cache_max": 0x1E9C,
|
|
"cache_ratio": 0x1EB0, "frame": 0x2878,
|
|
"buffered": 0x28E0, "shape_chars": 0x28E4,
|
|
"rt_aa": 0x1F2C, "quality": 0x1E98, "rt_disabled": 0x2295,
|
|
"slice": 0x2298, "slice_bounds": 0x229C},
|
|
"ps3": {"o2w": 0x318, "mode": 0x1CF8, "exporter": 0x21A8,
|
|
"scale": 0x19CC, "matrix": 0x19E4, "cache_max": 0x1940,
|
|
"cache_ratio": 0x1954, "frame": 0x2198,
|
|
"buffered": 0x21F8, "shape_chars": 0x21FC,
|
|
"rt_aa": 0x19BC, "quality": 0x193C, "rt_disabled": 0x1CF9,
|
|
"slice": 0x1CFC, "slice_bounds": 0x1D00},
|
|
"vita": {"o2w": 0x318, "mode": 0x1CF8, "exporter": 0x21A8,
|
|
"scale": 0x19CC, "matrix": 0x19E4, "cache_max": 0x1940,
|
|
"cache_ratio": 0x1954, "frame": 0x2198,
|
|
"buffered": 0x21F8, "shape_chars": 0x21FC,
|
|
"rt_aa": 0x19BC, "quality": 0x193C, "rt_disabled": 0x1CF9,
|
|
"slice": 0x1CFC, "slice_bounds": 0x1D00},
|
|
}
|
|
|
|
|
|
class PackedPrimitive(ctypes.Structure):
|
|
_fields_ = [
|
|
("vertices", ctypes.c_size_t), ("indices", ctypes.c_size_t),
|
|
("vertex_count", ctypes.c_int32), ("index_count", ctypes.c_int32),
|
|
("joins_previous", ctypes.c_uint8), ("vertex_format", ctypes.c_uint8),
|
|
("reserved", ctypes.c_uint16),
|
|
]
|
|
|
|
|
|
class VertexBufferSection(ctypes.Structure):
|
|
_fields_ = [
|
|
("primitives", ctypes.POINTER(PackedPrimitive)),
|
|
("primitive_count", ctypes.c_uint16), ("status", ctypes.c_uint8),
|
|
("flags", ctypes.c_uint8), ("bounds", ctypes.c_float * 4),
|
|
("inverse", ctypes.c_float * 4),
|
|
]
|
|
|
|
|
|
class VisibleGlyph(ctypes.Structure):
|
|
_fields_ = [
|
|
("font", ctypes.c_void_p), ("glyph", ctypes.c_int32),
|
|
("scale_x", ctypes.c_float), ("scale_y", ctypes.c_float),
|
|
]
|
|
|
|
|
|
class ShapeOwner(ctypes.Structure):
|
|
_fields_ = [
|
|
("cache_head", ctypes.c_void_p),
|
|
("section_count", ctypes.c_int16),
|
|
("cache_policy", ctypes.c_uint8),
|
|
("indirect_owner", ctypes.c_uint8),
|
|
("allocator_owner", ctypes.c_void_p),
|
|
("section_sources", ctypes.c_void_p),
|
|
]
|
|
|
|
|
|
class ExpShapeStats(ctypes.Structure):
|
|
_fields_ = [
|
|
("id", ctypes.c_uint64), ("cache_entry", ctypes.c_size_t),
|
|
("reserved", ctypes.c_uint32), ("sections", ctypes.c_uint32),
|
|
("draws", ctypes.c_uint32), ("vertices", ctypes.c_uint32),
|
|
("indices", ctypes.c_uint32), ("vertex_buffer_bytes", ctypes.c_uint32),
|
|
("textures", ctypes.c_size_t * 32),
|
|
("bitmap_records", ctypes.c_size_t * 64),
|
|
("texture_count", ctypes.c_int32), ("bitmap_count", ctypes.c_int32),
|
|
]
|
|
|
|
|
|
class ReconstructedSwfDrawShapeTests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
missing = [str(path) for path in (SOURCE, HEADER) if not path.exists()]
|
|
if missing:
|
|
raise AssertionError("missing reconstructed swf_draw_shape source/header: " +
|
|
", ".join(missing))
|
|
cls.temp = tempfile.TemporaryDirectory()
|
|
build = Path(os.environ.get("IGGY_TEST_BUILD_DIR", cls.temp.name))
|
|
build.mkdir(parents=True, exist_ok=True)
|
|
cls.libs = {}
|
|
for platform, define in VARIANTS.items():
|
|
output = build / f"swf_draw_shape_{platform}.dylib"
|
|
result = subprocess.run([
|
|
"clang", "-dynamiclib", "-std=c11", "-O2", "-Wall", "-Wextra",
|
|
"-Werror", f"-D{define}=1", "-I", str(RECONSTRUCTED),
|
|
str(SOURCE), str(SUPPORT),
|
|
*shlex.split(os.environ.get("IGGY_TEST_CFLAGS", "")),
|
|
"-o", str(output),
|
|
], capture_output=True, text=True)
|
|
if result.returncode:
|
|
raise AssertionError((platform, result.stdout + result.stderr))
|
|
library = ctypes.CDLL(str(output))
|
|
cls.configure(library)
|
|
cls.libs[platform] = library
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
cls.temp.cleanup()
|
|
|
|
@staticmethod
|
|
def configure(lib):
|
|
lib.shape_test_reset.argtypes = []
|
|
lib.shape_test_install_telemetry.argtypes = []
|
|
lib.shape_test_install_exporter.argtypes = [ctypes.c_void_p, ctypes.c_size_t]
|
|
lib.shape_test_set_draw_result.argtypes = [
|
|
ctypes.c_void_p, ctypes.c_size_t, ctypes.c_void_p]
|
|
lib.iggy_get_char_renderstate.argtypes = [
|
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
|
lib.iggy_draw_text_bitmap.argtypes = [
|
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p,
|
|
ctypes.c_float, ctypes.c_float, ctypes.c_float, ctypes.c_float,
|
|
ctypes.c_int32]
|
|
lib.iggy_draw_bitmap_raw.argtypes = [
|
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
|
lib.iggy_flush_textureinfo_for_iggyexp.argtypes = [
|
|
ctypes.c_void_p, ctypes.c_void_p]
|
|
lib.iggy_draw_shape_raw.argtypes = [
|
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_float, ctypes.c_void_p,
|
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p,
|
|
ctypes.c_uint32, ctypes.c_int32]
|
|
lib.iggy_draw_shape_raw.restype = ctypes.c_int32
|
|
lib.iggy_get_shape_stats.argtypes = [
|
|
ctypes.c_void_p, ctypes.c_uint64, ctypes.c_void_p,
|
|
ctypes.c_float, ctypes.c_void_p, ctypes.c_void_p]
|
|
lib.iggy_draw_char.argtypes = [
|
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_float, ctypes.c_int32,
|
|
ctypes.c_float, ctypes.c_float, ctypes.c_void_p, ctypes.c_void_p]
|
|
lib.iggy_iggyexp_char.argtypes = [
|
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_float, ctypes.c_int32,
|
|
ctypes.POINTER(ExpShapeStats)]
|
|
lib.iggy_fontcache_char.argtypes = [
|
|
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_float, ctypes.c_int32,
|
|
ctypes.c_float, ctypes.c_float, ctypes.c_void_p,
|
|
ctypes.POINTER(VisibleGlyph), ctypes.POINTER(ctypes.c_int32),
|
|
ctypes.c_float, ctypes.c_float]
|
|
lib.shape_test_cacheable_callback.argtypes = [
|
|
ctypes.c_void_p, ctypes.c_int32, ctypes.c_float]
|
|
lib.shape_test_cacheable_callback.restype = ctypes.c_int32
|
|
|
|
def setUp(self):
|
|
for lib in self.libs.values():
|
|
lib.shape_test_reset()
|
|
ctypes.c_uint8.in_dll(lib, "iggy_fix_bitmap_smoothing").value = 1
|
|
|
|
@staticmethod
|
|
def integer(lib, name):
|
|
return ctypes.c_int.in_dll(lib, name).value
|
|
|
|
@staticmethod
|
|
def floats(lib, name, count):
|
|
return tuple((ctypes.c_float * count).in_dll(lib, name))
|
|
|
|
@staticmethod
|
|
def player(platform):
|
|
player = (ctypes.c_uint8 * 0x3600)()
|
|
offsets = OFFSETS[platform]
|
|
ctypes.c_float.from_buffer(player, offsets["scale"]).value = 2.0
|
|
ctypes.c_float.from_buffer(player, offsets["scale"] + 4).value = 3.0
|
|
matrix = (ctypes.c_float * 6).from_buffer(player, offsets["matrix"])
|
|
matrix[:] = (1, 0, 0, 1, 0, 0)
|
|
return player
|
|
|
|
@staticmethod
|
|
def font(glyph_count=1):
|
|
font = (ctypes.c_uint8 * 0x100)()
|
|
ctypes.c_int32.from_buffer(font, 0x34).value = glyph_count
|
|
return font
|
|
|
|
@staticmethod
|
|
def set_cache_limits(player, platform, maximum=1000.0):
|
|
offsets = OFFSETS[platform]
|
|
ctypes.c_float.from_buffer(player, offsets["cache_max"]).value = maximum
|
|
ctypes.c_float.from_buffer(player, offsets["cache_max"] + 4).value = maximum
|
|
ctypes.c_float.from_buffer(player, offsets["cache_ratio"]).value = 0.5
|
|
ctypes.c_float.from_buffer(player, offsets["cache_ratio"] + 4).value = 2.0
|
|
|
|
def test_get_char_renderstate_sets_exact_flags_transform_and_mode(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
state = (ctypes.c_uint8 * 240)()
|
|
rgba = (ctypes.c_uint8 * 4)(1, 2, 3, 4)
|
|
transform = (ctypes.c_uint8 * 64)()
|
|
transform[1] = 1
|
|
ctypes.c_void_p.from_buffer(player, OFFSETS[platform]["o2w"]).value = 0x12345678
|
|
player[OFFSETS[platform]["mode"]] = 0
|
|
|
|
lib.iggy_get_char_renderstate(
|
|
player, state, rgba, ctypes.byref(transform))
|
|
|
|
self.assertEqual(self.integer(lib, "shape_test_clear_calls"), 1, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_setcolor_calls"), 1, platform)
|
|
self.assertEqual(state[12], 1, platform)
|
|
self.assertEqual(ctypes.c_uint32.from_buffer(state, 4).value & 4, 0, platform)
|
|
self.assertEqual(state[9], 2, platform)
|
|
self.assertEqual(ctypes.c_void_p.from_buffer(state, 24).value,
|
|
ctypes.addressof(transform) + 0x14, platform)
|
|
self.assertEqual(ctypes.c_void_p.from_buffer(state, 32).value,
|
|
0x12345678, platform)
|
|
player[OFFSETS[platform]["mode"]] = 1
|
|
transform[1] = 0
|
|
lib.iggy_get_char_renderstate(player, state, rgba, transform)
|
|
self.assertEqual(state[9], 5, platform)
|
|
self.assertIsNone(ctypes.c_void_p.from_buffer(state, 24).value, platform)
|
|
|
|
def test_text_bitmap_uses_canonical_argument_order_and_rectangle(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
bitmap = (ctypes.c_uint8 * 64)()
|
|
transform = (ctypes.c_uint8 * 64)()
|
|
lib.iggy_draw_text_bitmap(
|
|
player, bitmap, transform, 10.0, 20.0, 30.0, 40.0, 7)
|
|
self.assertEqual(self.integer(lib, "shape_test_setup_bitmap_calls"), 1,
|
|
platform)
|
|
self.assertEqual(ctypes.c_size_t.in_dll(
|
|
lib, "shape_test_setup_resource").value, ctypes.addressof(bitmap))
|
|
self.assertEqual(self.integer(lib, "shape_test_last_smoothing"), 7)
|
|
self.assertEqual(self.floats(lib, "shape_test_rectangle", 8),
|
|
(10, 20, 40, 60, 0, 0, 1, 1), platform)
|
|
state = (ctypes.c_uint8 * 240).in_dll(lib, "shape_test_captured_state")
|
|
self.assertEqual(ctypes.c_uint32.from_buffer(state, 4).value & 4, 0)
|
|
self.assertEqual(state[16], 0)
|
|
self.assertEqual(self.integer(lib, "shape_test_unlock_calls"), 1)
|
|
|
|
def test_bitmap_raw_direct_texture_and_embedded_bitmap_routes(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
obj = (ctypes.c_uint8 * 0x180)()
|
|
texture = (ctypes.c_uint8 * 0x50)()
|
|
transform = (ctypes.c_uint8 * 32)()
|
|
is_64 = ctypes.sizeof(ctypes.c_void_p) == 8
|
|
direct_offset = 0x148 if is_64 else 0xE8
|
|
width_offset = 0x28 if is_64 else 0x14
|
|
height_offset = 0x2C if is_64 else 0x18
|
|
flag_offset = 0xBB if is_64 else 0x63
|
|
ctypes.c_void_p.from_buffer(obj, direct_offset).value = ctypes.addressof(texture)
|
|
ctypes.c_int32.from_buffer(texture, width_offset).value = 37
|
|
ctypes.c_int32.from_buffer(texture, height_offset).value = 19
|
|
obj[flag_offset] = 0x10
|
|
lib.iggy_draw_bitmap_raw(player, obj, transform)
|
|
self.assertEqual(self.integer(lib, "shape_test_setup_texture_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_last_smoothing"), 0,
|
|
platform)
|
|
self.assertEqual(self.floats(lib, "shape_test_texgen", 4),
|
|
(0, 0, 37, 19), platform)
|
|
|
|
lib.shape_test_reset()
|
|
ctypes.c_uint8.in_dll(lib, "iggy_fix_bitmap_smoothing").value = 1
|
|
obj = (ctypes.c_uint8 * 0x180)()
|
|
bitmap = (ctypes.c_uint8 * 0x50)()
|
|
bitmap[0] = 4
|
|
ctypes.c_int16.from_buffer(bitmap, 2).value = 1
|
|
bitmap_width = 0x20 if is_64 else 0x10
|
|
ctypes.c_int16.from_buffer(bitmap, bitmap_width).value = -7
|
|
ctypes.c_int16.from_buffer(bitmap, bitmap_width + 2).value = 11
|
|
ctypes.c_void_p.from_buffer(obj, 0xA8 if is_64 else 0x58).value = \
|
|
ctypes.addressof(bitmap)
|
|
lib.iggy_draw_bitmap_raw(player, obj, transform)
|
|
self.assertEqual(self.integer(lib, "shape_test_setup_bitmap_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_last_smoothing"), 1,
|
|
platform)
|
|
self.assertEqual(self.floats(lib, "shape_test_texgen", 4),
|
|
(0, 0, -7, 11), platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_unlock_calls"), 1)
|
|
|
|
def test_bitmap_raw_indirect_resource_and_null_sentinel(self):
|
|
for platform in ("durango", "orbis"):
|
|
lib = self.libs[platform]
|
|
player = self.player(platform)
|
|
obj = (ctypes.c_uint8 * 0x180)()
|
|
bitmap = (ctypes.c_uint8 * 0x60)()
|
|
resource = (ctypes.c_uint8 * 0x40)()
|
|
slot = (ctypes.c_void_p * 1)()
|
|
is_64 = ctypes.sizeof(ctypes.c_void_p) == 8
|
|
indirect_offset = 0x150 if is_64 else 0xEC
|
|
bitmap_pointer_offset = 0x27 if is_64 else 0x17
|
|
size_offset = 0x20 if is_64 else 0x10
|
|
ctypes.c_int16.from_buffer(bitmap, size_offset).value = 23
|
|
ctypes.c_int16.from_buffer(bitmap, size_offset + 2).value = 29
|
|
ctypes.c_void_p.from_buffer(resource, bitmap_pointer_offset).value = \
|
|
ctypes.addressof(bitmap)
|
|
slot[0] = ctypes.addressof(resource)
|
|
ctypes.c_void_p.from_buffer(obj, indirect_offset).value = ctypes.addressof(slot)
|
|
|
|
lib.iggy_draw_bitmap_raw(player, obj, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_setup_bitmap_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.floats(lib, "shape_test_texgen", 4),
|
|
(0, 0, 23, 29), platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_unlock_calls"), 1,
|
|
platform)
|
|
|
|
lib.shape_test_reset()
|
|
sentinel = (ctypes.c_uint8 * 16).in_dll(
|
|
lib, "as3vm_nullundef_storage")
|
|
slot[0] = ctypes.addressof(sentinel) + 1
|
|
lib.iggy_draw_bitmap_raw(player, obj, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_setup_bitmap_calls"), 0,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_texgen_calls"), 0,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_unlock_calls"), 0,
|
|
platform)
|
|
|
|
def test_exporter_flush_chunks_texture_and_glyph_queues(self):
|
|
for platform in ("durango", "orbis"):
|
|
lib = self.libs[platform]
|
|
player = self.player(platform)
|
|
lib.shape_test_install_exporter(player, OFFSETS[platform]["exporter"])
|
|
stats = (ctypes.c_uint8 * 0x330)()
|
|
ctypes.c_uint64.from_buffer(stats, 0).value = 0x1122334455667788
|
|
handles = (ctypes.c_size_t * 17).from_buffer(stats, 0x28)
|
|
for index in range(17):
|
|
handles[index] = 0x1000 + index
|
|
ctypes.c_int32.from_buffer(stats, 0x328).value = 17
|
|
glyphs = [(ctypes.c_uint8 * 0x60)() for _ in range(33)]
|
|
glyph_slots = (ctypes.c_size_t * 33).from_buffer(stats, 0x128)
|
|
for index, glyph in enumerate(glyphs):
|
|
ctypes.c_int16.from_buffer(glyph, 0x4C).value = index + 1
|
|
ctypes.c_int16.from_buffer(glyph, 0x4E).value = index + 2
|
|
glyph_slots[index] = ctypes.addressof(glyph)
|
|
ctypes.c_int32.from_buffer(stats, 0x32C).value = 33
|
|
|
|
lib.iggy_flush_textureinfo_for_iggyexp(player, stats)
|
|
|
|
self.assertEqual(self.integer(lib, "shape_test_export_calls"), 2,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_describe_calls"), 17,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_last_event"), 0x88)
|
|
self.assertEqual(self.integer(lib, "shape_test_last_packet_size"), 0x330)
|
|
self.assertEqual(ctypes.c_int32.from_buffer(stats, 0x328).value, 0)
|
|
self.assertEqual(ctypes.c_int32.from_buffer(stats, 0x32C).value, 0)
|
|
packets = ((ctypes.c_uint8 * 0x330) * 4).in_dll(lib, "shape_test_packets")
|
|
self.assertEqual(ctypes.c_uint64.from_buffer(packets[0], 0).value,
|
|
0x1122334455667788)
|
|
self.assertEqual(ctypes.c_uint64.from_buffer(packets[0], 0x28).value,
|
|
0x1000)
|
|
self.assertEqual(ctypes.c_uint64.from_buffer(packets[1], 0x28).value,
|
|
0x1010)
|
|
self.assertEqual(ctypes.c_uint64.from_buffer(packets[1], 0x128).value,
|
|
ctypes.addressof(glyphs[32]))
|
|
self.assertEqual(
|
|
(ctypes.c_int32.from_buffer(packets[0], 0x328).value,
|
|
ctypes.c_int32.from_buffer(packets[0], 0x32C).value),
|
|
(16, 32), platform)
|
|
self.assertEqual(
|
|
(ctypes.c_int32.from_buffer(packets[1], 0x328).value,
|
|
ctypes.c_int32.from_buffer(packets[1], 0x32C).value),
|
|
(1, 1), platform)
|
|
|
|
def test_exporter_null_callback_still_describes_and_drains(self):
|
|
for platform in ("durango", "orbis"):
|
|
lib = self.libs[platform]
|
|
player = self.player(platform)
|
|
stats = (ctypes.c_uint8 * 0x330)()
|
|
ctypes.c_size_t.from_buffer(stats, 0x28).value = 0x4444
|
|
ctypes.c_int32.from_buffer(stats, 0x328).value = 1
|
|
lib.iggy_flush_textureinfo_for_iggyexp(player, stats)
|
|
self.assertEqual(self.integer(lib, "shape_test_describe_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_export_calls"), 0,
|
|
platform)
|
|
self.assertEqual(ctypes.c_int32.from_buffer(stats, 0x328).value, 0,
|
|
platform)
|
|
|
|
def test_shape_stats_emits_native_counter_packet(self):
|
|
for platform in ("durango", "orbis"):
|
|
lib = self.libs[platform]
|
|
player = self.player(platform)
|
|
lib.shape_test_install_exporter(player, OFFSETS[platform]["exporter"])
|
|
shape = (ctypes.c_uint8 * 32)()
|
|
ctypes.c_int.in_dll(lib, "shape_test_measure_result").value = 1
|
|
lib.iggy_get_shape_stats(player, 0x8877665544332211,
|
|
shape, 0.25, None, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_measure_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_export_calls"), 1,
|
|
platform)
|
|
packets = ((ctypes.c_uint8 * 0x330) * 4).in_dll(
|
|
lib, "shape_test_packets")
|
|
self.assertEqual(ctypes.c_uint64.from_buffer(packets[0], 0).value,
|
|
0x8877665544332211)
|
|
self.assertEqual(ctypes.c_uint64.from_buffer(packets[0], 8).value,
|
|
0x1020)
|
|
self.assertEqual(tuple(ctypes.c_uint32.from_buffer(
|
|
packets[0], 0x10 + index * 4).value for index in range(5)),
|
|
(2, 3, 4, 5, 6))
|
|
|
|
@staticmethod
|
|
def shape_with_fills(platform, fill_count):
|
|
shape = (ctypes.c_uint8 * 32)()
|
|
source = (ctypes.c_uint8 * 0x40)()
|
|
fills = (ctypes.c_uint8 * (8 + max(fill_count, 1) * 0x48))()
|
|
ctypes.c_int16.from_buffer(shape, 8).value = 1
|
|
ctypes.c_void_p.from_buffer(shape, 24).value = ctypes.addressof(source)
|
|
ctypes.c_int32.from_buffer(fills, 0).value = fill_count
|
|
fill_offset = 0x20 if ctypes.sizeof(ctypes.c_void_p) == 8 else 0x18
|
|
ctypes.c_void_p.from_buffer(source, fill_offset).value = ctypes.addressof(fills)
|
|
return shape, source, fills
|
|
|
|
def test_shape_stats_fill_textures_flush_at_32_and_zero_bitmap(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
shape, source, fills = self.shape_with_fills(platform, 33)
|
|
lib.iggy_get_shape_stats(
|
|
player, 0x4444, shape, 0.0, None, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_fill_texture_calls"), 33,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_export_calls"), 0,
|
|
platform)
|
|
|
|
lib.shape_test_reset()
|
|
lib.shape_test_install_exporter(player, OFFSETS[platform]["exporter"])
|
|
ctypes.c_size_t.in_dll(
|
|
lib, "shape_test_fill_texture_result").value = 0x7777
|
|
lib.iggy_get_shape_stats(
|
|
player, 0x5555, shape, 0.0, None, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_fill_texture_calls"), 33,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_describe_calls"), 33,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_export_calls"), 3,
|
|
platform)
|
|
packets = ((ctypes.c_uint8 * 0x330) * 4).in_dll(
|
|
lib, "shape_test_packets")
|
|
self.assertEqual(ctypes.c_uint64.from_buffer(
|
|
packets[0], 0x28).value, 0x7777, platform)
|
|
self.assertEqual(ctypes.c_uint64.from_buffer(
|
|
packets[2], 0x28).value, 0x7777, platform)
|
|
|
|
lib.shape_test_reset()
|
|
stats = ExpShapeStats(id=0x6666, bitmap_count=1)
|
|
lib.iggy_flush_textureinfo_for_iggyexp(player, ctypes.byref(stats))
|
|
self.assertEqual(self.integer(lib, "shape_test_export_calls"), 1,
|
|
platform)
|
|
packets = ((ctypes.c_uint8 * 0x330) * 4).in_dll(
|
|
lib, "shape_test_packets")
|
|
self.assertEqual(bytes(packets[0][0x128:0x138]), bytes(16), platform)
|
|
|
|
def test_cached_vertex_buffer_filters_primitive_formats(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
shape, source, fills = self.shape_with_fills(platform, 1)
|
|
source[0x38 if ctypes.sizeof(ctypes.c_void_p) == 8 else 0x24] = 1
|
|
primitives = (PackedPrimitive * 3)()
|
|
primitives[0].vertex_format = 4
|
|
primitives[1].vertex_format = 1
|
|
primitives[2].vertex_format = 5
|
|
section = VertexBufferSection(primitives, 3, 9, 0)
|
|
lib.shape_test_set_draw_result(None, 0xABCDEF, ctypes.byref(section))
|
|
result = lib.iggy_draw_shape_raw(
|
|
player, shape, 0.0, None, None, None, None, 0, 0)
|
|
self.assertEqual(result, 1, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_draw_batch_calls"), 2,
|
|
platform)
|
|
formats = (ctypes.c_uint8 * 16).in_dll(
|
|
lib, "shape_test_drawn_vertex_formats")
|
|
self.assertEqual(tuple(formats[:2]), (1, 5), platform)
|
|
self.assertEqual(ctypes.c_size_t.in_dll(
|
|
lib, "shape_test_last_vertex_buffer").value, 0xABCDEF)
|
|
self.assertEqual(self.integer(lib, "shape_test_unlock_calls"), 1)
|
|
|
|
def test_render_target_aa_nested_composite_and_all_cleanup(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
offsets = OFFSETS[platform]
|
|
ctypes.c_int32.from_buffer(player, offsets["rt_aa"]).value = 1
|
|
ctypes.c_int32.from_buffer(player, offsets["quality"]).value = 10
|
|
ctypes.c_int32.from_buffer(player, offsets["slice"]).value = 1
|
|
ctypes.c_int32.from_buffer(player, offsets["slice_bounds"]).value = 1
|
|
shape, source, fills = self.shape_with_fills(platform, 2)
|
|
source[0x38 if ctypes.sizeof(ctypes.c_void_p) == 8 else 0x24] = 1
|
|
slice_bounds = (ctypes.c_float * 8)(0, 0, 4, 4, 1, 1, 5, 5)
|
|
ctypes.c_void_p.from_buffer(source, 0x30).value = \
|
|
ctypes.addressof(slice_bounds)
|
|
primitive_arrays = [(PackedPrimitive * 1)() for _ in range(2)]
|
|
sections = (VertexBufferSection * 2)()
|
|
for index in range(2):
|
|
primitive_arrays[index][0].vertex_format = 1
|
|
sections[index].primitives = primitive_arrays[index]
|
|
sections[index].primitive_count = 1
|
|
sections[index].flags = 1
|
|
sections[0].bounds[:] = (2, 2, 5, 5)
|
|
sections[1].bounds[:] = (1, 3, 6, 4)
|
|
lib.shape_test_set_draw_result(None, 0x7777, sections)
|
|
bounds = (ctypes.c_float * 4)(1, 2, 3, 4)
|
|
matrix = (ctypes.c_float * 6)(1, 0, 0, 1, 0, 0)
|
|
|
|
result = lib.iggy_draw_shape_raw(
|
|
player, shape, 0.0, None, None, bounds, matrix, 0, 0)
|
|
self.assertEqual(result, 1, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_compute_bounds_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_start_nested_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(
|
|
lib, "shape_test_start_nested_needs_identifier"), 1, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_end_nested_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_screen_rect_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_free_texture_calls"), 1,
|
|
platform)
|
|
order_count = self.integer(lib, "shape_test_call_order_count")
|
|
order = (ctypes.c_uint8 * 64).in_dll(lib, "shape_test_call_order")
|
|
self.assertEqual(tuple(order[:order_count]),
|
|
(1, 2, 3, 3, 4, 5, 6, 7, 8, 7), platform)
|
|
self.assertEqual(ctypes.c_size_t.in_dll(
|
|
lib, "shape_test_fill_new_bounds").value,
|
|
ctypes.addressof(slice_bounds) + 16, platform)
|
|
self.assertEqual(ctypes.c_size_t.in_dll(
|
|
lib, "shape_test_fill_old_bounds").value,
|
|
ctypes.addressof(sections[1]) + VertexBufferSection.bounds.offset,
|
|
platform)
|
|
self.assertEqual(ctypes.c_size_t.in_dll(
|
|
lib, "shape_test_fill_extra_matrix").value,
|
|
ctypes.addressof(matrix), platform)
|
|
|
|
gates = (
|
|
("rt-off", bounds, matrix, 0, 0, 0, 10, 0, 1),
|
|
("quality", bounds, matrix, 0, 0, 1, 9, 0, 1),
|
|
("disabled-byte", bounds, matrix, 0, 0, 1, 10, 1, 1),
|
|
("disable-arg", bounds, matrix, 1, 0, 1, 10, 0, 1),
|
|
("suppress-arg", bounds, matrix, 0, 1, 1, 10, 0, 1),
|
|
("null-bounds", None, matrix, 0, 0, 1, 10, 0, 1),
|
|
("null-matrix", bounds, None, 0, 0, 1, 10, 0, 1),
|
|
("one-eligible", bounds, matrix, 0, 0, 1, 10, 0, 0),
|
|
)
|
|
for (gate, gate_bounds, gate_matrix, disable_arg, suppress_arg,
|
|
aa_enabled, quality, disabled_byte, second_flags) in gates:
|
|
lib.shape_test_reset()
|
|
ctypes.c_uint8.in_dll(lib, "iggy_fix_bitmap_smoothing").value = 1
|
|
ctypes.c_int32.from_buffer(player, offsets["rt_aa"]).value = aa_enabled
|
|
ctypes.c_int32.from_buffer(player, offsets["quality"]).value = quality
|
|
player[offsets["rt_disabled"]] = disabled_byte
|
|
sections[1].flags = second_flags
|
|
lib.shape_test_set_draw_result(None, 0x7777, sections)
|
|
lib.iggy_draw_shape_raw(
|
|
player, shape, 0.0, None, None, gate_bounds, gate_matrix,
|
|
disable_arg, suppress_arg)
|
|
self.assertEqual(self.integer(lib, "shape_test_start_nested_calls"),
|
|
0, (platform, gate))
|
|
|
|
lib.shape_test_reset()
|
|
ctypes.c_int32.from_buffer(player, offsets["rt_aa"]).value = 1
|
|
ctypes.c_int32.from_buffer(player, offsets["quality"]).value = 10
|
|
player[offsets["rt_disabled"]] = 0
|
|
sections[1].flags = 1
|
|
lib.shape_test_set_draw_result(None, 0x7777, sections)
|
|
ctypes.c_int.in_dll(lib, "shape_test_start_nested_result").value = 0
|
|
lib.iggy_draw_shape_raw(
|
|
player, shape, 0.0, None, None, bounds, matrix, 0, 0)
|
|
self.assertEqual(self.integer(lib, "shape_test_start_nested_calls"), 1)
|
|
self.assertEqual(self.integer(lib, "shape_test_end_nested_calls"), 0)
|
|
self.assertEqual(self.integer(lib, "shape_test_screen_rect_calls"), 0)
|
|
self.assertEqual(self.integer(lib, "shape_test_free_texture_calls"), 0)
|
|
self.assertEqual(self.integer(lib, "shape_test_unlock_calls"), 0)
|
|
|
|
def test_stroke_predraw_and_path_respect_section_gate(self):
|
|
for platform in ("durango", "orbis"):
|
|
lib = self.libs[platform]
|
|
player = self.player(platform)
|
|
shape, source, fills = self.shape_with_fills(platform, 0)
|
|
is_64 = ctypes.sizeof(ctypes.c_void_p) == 8
|
|
source_path_offset = 0x10
|
|
strokes_offset = 0x28 if is_64 else 0x1C
|
|
flags_offset = 0x38 if is_64 else 0x24
|
|
strokes = (ctypes.c_uint8 * 0x80)()
|
|
ctypes.c_int32.from_buffer(strokes, 0).value = 1
|
|
ctypes.c_void_p.from_buffer(source, source_path_offset).value = 0x1234
|
|
ctypes.c_void_p.from_buffer(source, strokes_offset).value = \
|
|
ctypes.addressof(strokes)
|
|
lib.iggy_draw_shape_raw(
|
|
player, shape, 0.0, None, None, None, None, 0, 0)
|
|
self.assertEqual(self.integer(lib, "shape_test_predraw_stroke_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_stroke_path_calls"), 1,
|
|
platform)
|
|
self.assertEqual(ctypes.c_size_t.in_dll(
|
|
lib, "shape_test_last_stroke_path").value, 0x1234, platform)
|
|
lib.shape_test_reset()
|
|
source[flags_offset] = 1
|
|
lib.iggy_draw_shape_raw(
|
|
player, shape, 0.0, None, None, None, None, 0, 0)
|
|
self.assertEqual(self.integer(lib, "shape_test_predraw_stroke_calls"), 0,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_stroke_path_calls"), 0,
|
|
platform)
|
|
|
|
def test_character_cached_bitmap_cached_vector_and_fontcache_queue(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
offsets = OFFSETS[platform]
|
|
ctypes.c_float.from_buffer(player, offsets["cache_max"]).value = 1000
|
|
ctypes.c_float.from_buffer(player, offsets["cache_max"] + 4).value = 1000
|
|
ctypes.c_float.from_buffer(player, offsets["cache_ratio"]).value = 0.5
|
|
ctypes.c_float.from_buffer(player, offsets["cache_ratio"] + 4).value = 2.0
|
|
ctypes.c_int32.from_buffer(player, offsets["frame"]).value = 77
|
|
is_64 = ctypes.sizeof(ctypes.c_void_p) == 8
|
|
font = (ctypes.c_uint8 * 0x100)()
|
|
glyph_count = 0x34 if is_64 else 0x20
|
|
heads_offset = 0x40 if is_64 else 0x28
|
|
record_scale = 0x30 if is_64 else 0x20
|
|
record_rect = 0x38 if is_64 else 0x28
|
|
record_frame = 0x48 if is_64 else 0x38
|
|
record_slot = 0x5C if is_64 else 0x4C
|
|
ctypes.c_int32.from_buffer(font, glyph_count).value = 1
|
|
heads = (ctypes.c_void_p * 1)()
|
|
record = (ctypes.c_uint8 * 0x70)()
|
|
heads[0] = ctypes.addressof(record)
|
|
ctypes.c_void_p.from_buffer(font, heads_offset).value = ctypes.addressof(heads)
|
|
ctypes.c_float.from_buffer(record, record_scale).value = 2.0
|
|
ctypes.c_float.from_buffer(record, record_scale + 4).value = 3.0
|
|
(ctypes.c_float * 4).from_buffer(record, record_rect)[:] = (1, 2, 4, 6)
|
|
(ctypes.c_float * 4).from_buffer(record, 0x20 if is_64 else 0x10)[:] = \
|
|
(0.1, 0.2, 0.8, 0.9)
|
|
ctypes.c_int16.from_buffer(record, record_slot).value = 5
|
|
rgba = (ctypes.c_uint8 * 4)(255, 255, 255, 255)
|
|
lib.iggy_draw_char(player, font, 1.0, 0, 10, 20, rgba, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_buffered_rect_calls"), 1,
|
|
platform)
|
|
rectangle = self.floats(lib, "shape_test_buffered_rect", 8)
|
|
self.assertEqual(rectangle[:4], (11, 22, 14, 26), platform)
|
|
for actual, expected in zip(rectangle[4:], (0.1, 0.2, 0.8, 0.9)):
|
|
self.assertAlmostEqual(actual, expected, places=6, msg=platform)
|
|
self.assertEqual(ctypes.c_int32.from_buffer(record, record_frame).value,
|
|
77, platform)
|
|
self.assertEqual(ctypes.c_int32.from_buffer(
|
|
player, offsets["buffered"]).value, 1, platform)
|
|
|
|
lib.shape_test_reset()
|
|
ctypes.c_void_p.from_buffer(font, heads_offset).value = 0
|
|
visible = (VisibleGlyph * 2)()
|
|
count = ctypes.c_int32()
|
|
lib.iggy_fontcache_char(
|
|
player, font, 2.0, 0, 0, 0, None,
|
|
visible, ctypes.byref(count), 3.0, 4.0)
|
|
self.assertEqual(count.value, 1, platform)
|
|
self.assertEqual((visible[0].font, visible[0].glyph,
|
|
visible[0].scale_x, visible[0].scale_y),
|
|
(ctypes.addressof(font), 0, 6.0, 8.0), platform)
|
|
|
|
lib.shape_test_reset()
|
|
owner = (ctypes.c_uint8 * 32)()
|
|
source = (ctypes.c_uint8 * 0x40)()
|
|
ctypes.c_int16.from_buffer(owner, 8).value = 1
|
|
ctypes.c_void_p.from_buffer(owner, 24).value = ctypes.addressof(source)
|
|
cache = (ctypes.c_void_p * 1)(ctypes.addressof(owner))
|
|
ctypes.c_void_p.from_buffer(font, 0x48 if is_64 else 0x2C).value = \
|
|
ctypes.addressof(cache)
|
|
ctypes.c_void_p.from_buffer(font, 0xC8 if is_64 else 0x80).value = 1
|
|
ctypes.c_float.from_buffer(player, offsets["cache_max"]).value = 0
|
|
ctypes.c_float.from_buffer(player, offsets["cache_max"] + 4).value = 0
|
|
primitive = PackedPrimitive(vertex_format=5)
|
|
section = VertexBufferSection(ctypes.pointer(primitive), 1, 9, 0)
|
|
lib.shape_test_set_draw_result(None, 0x5151, ctypes.byref(section))
|
|
ctypes.c_int.in_dll(lib, "shape_test_onesection_result").value = 1
|
|
lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_onesection_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_get_shape_calls"), 0,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_draw_batch_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_lowlevel_xform_calls"), 2,
|
|
platform)
|
|
|
|
def test_character_fallback_callback_empty_and_fontcache_limits(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
self.set_cache_limits(player, platform)
|
|
rgba = (ctypes.c_uint8 * 4)(255, 255, 255, 255)
|
|
|
|
lib.iggy_draw_char(player, None, 1.0, 0, 0, 0, rgba, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_glyph_empty_calls"), 0,
|
|
platform)
|
|
|
|
font = self.font()
|
|
lib.iggy_draw_char(player, font, 1.0, 1, 0, 0, rgba, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_fallback_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_glyph_empty_calls"), 0,
|
|
platform)
|
|
|
|
fallback = self.font()
|
|
ctypes.c_size_t.in_dll(lib, "shape_test_fallback_font").value = \
|
|
ctypes.addressof(fallback)
|
|
ctypes.c_int.in_dll(lib, "shape_test_glyph_empty").value = 1
|
|
lib.iggy_draw_char(player, font, 1.0, 1, 0, 0, rgba, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_last_glyph"), 0, platform)
|
|
|
|
lib.shape_test_reset()
|
|
font = self.font()
|
|
font[0xE0] = 1
|
|
callback = ctypes.cast(
|
|
lib.shape_test_cacheable_callback, ctypes.c_void_p).value
|
|
ctypes.c_void_p.from_buffer(font, 0xD8).value = callback
|
|
visible = (VisibleGlyph * 2)()
|
|
count = ctypes.c_int32()
|
|
lib.iggy_fontcache_char(
|
|
player, font, 2.0, 0, 0, 0, None,
|
|
visible, ctypes.byref(count), 3.0, 4.0)
|
|
self.assertEqual(count.value, 0, platform)
|
|
|
|
self.assertEqual(self.integer(lib, "shape_test_cacheable_callback_calls"),
|
|
1, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_metrics_calls"), 0,
|
|
platform)
|
|
self.assertAlmostEqual(ctypes.c_float.in_dll(
|
|
lib, "shape_test_cacheable_callback_scale").value, 8.0,
|
|
places=6, msg=platform)
|
|
|
|
ctypes.c_void_p.from_buffer(font, 0xC8).value = 1
|
|
lib.iggy_fontcache_char(
|
|
player, font, 2.0, 0, 0, 0, None,
|
|
visible, ctypes.byref(count), 3.0, 4.0)
|
|
self.assertEqual(count.value, 1, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_metrics_calls"), 1,
|
|
platform)
|
|
count.value = 0
|
|
ctypes.c_void_p.from_buffer(font, 0xC8).value = 0
|
|
|
|
ctypes.c_int.in_dll(
|
|
lib, "shape_test_cacheable_callback_result").value = 1
|
|
lib.iggy_fontcache_char(
|
|
player, font, 2.0, 0, 0, 0, None,
|
|
visible, ctypes.byref(count), 3.0, 4.0)
|
|
self.assertEqual(count.value, 1, platform)
|
|
|
|
ctypes.c_int.in_dll(lib, "iggy_max_visible_chars").value = 1
|
|
lib.iggy_fontcache_char(
|
|
player, font, 2.0, 0, 0, 0, None,
|
|
visible, ctypes.byref(count), 3.0, 4.0)
|
|
self.assertEqual(count.value, 1, platform)
|
|
|
|
lib.shape_test_reset()
|
|
ctypes.c_int.in_dll(lib, "shape_test_glyph_empty").value = 1
|
|
count.value = 0
|
|
lib.iggy_fontcache_char(
|
|
player, font, 1.0, 0, 0, 0, None,
|
|
visible, ctypes.byref(count), 1.0, 1.0)
|
|
self.assertEqual(count.value, 0, platform)
|
|
|
|
lib.shape_test_reset()
|
|
font = self.font()
|
|
self.set_cache_limits(player, platform, 0.0)
|
|
lib.iggy_fontcache_char(
|
|
player, font, 1.0, 0, 0, 0, None,
|
|
visible, ctypes.byref(count), 1.0, 1.0)
|
|
self.assertEqual(count.value, 0, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_metrics_calls"), 1,
|
|
platform)
|
|
|
|
lib.shape_test_reset()
|
|
font = self.font()
|
|
font[0xE0] = 1
|
|
self.set_cache_limits(player, platform)
|
|
count.value = 0
|
|
lib.iggy_fontcache_char(
|
|
player, font, 1.0, 0, 0, 0, None,
|
|
visible, ctypes.byref(count), 1.0, 1.0)
|
|
self.assertEqual(count.value, 1, platform)
|
|
|
|
lib.shape_test_reset()
|
|
font = self.font()
|
|
self.set_cache_limits(player, platform)
|
|
ctypes.c_float.from_buffer(
|
|
player, OFFSETS[platform]["cache_max"]).value = 1.0
|
|
metrics = (ctypes.c_float * 6).in_dll(lib, "shape_test_metrics")
|
|
metrics[3] = 2.0
|
|
count.value = 0
|
|
lib.iggy_fontcache_char(
|
|
player, font, 1.0, 0, 0, 0, None,
|
|
visible, ctypes.byref(count), 1.0, 1.0)
|
|
self.assertEqual(count.value, 0, platform)
|
|
|
|
def test_fontcache_callback_presence_uses_the_native_pointer_width(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
self.set_cache_limits(player, platform)
|
|
font = self.font()
|
|
callback = ctypes.cast(
|
|
lib.shape_test_cacheable_callback, ctypes.c_void_p).value
|
|
for callback_offset, present_offset in ((0xD8, 0xE0),
|
|
(0x88, 0x8C)):
|
|
ctypes.c_void_p.from_buffer(font, callback_offset).value = callback
|
|
ctypes.c_size_t.from_buffer(font, present_offset).value = 0x100
|
|
visible = (VisibleGlyph * 1)()
|
|
count = ctypes.c_int32()
|
|
|
|
lib.iggy_fontcache_char(
|
|
player, font, 1.0, 0, 0, 0, None,
|
|
visible, ctypes.byref(count), 1.0, 1.0)
|
|
|
|
self.assertEqual(
|
|
self.integer(lib, "shape_test_cacheable_callback_calls"),
|
|
1, platform)
|
|
|
|
def test_character_cache_miss_chain_and_alternate_range(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
self.set_cache_limits(player, platform)
|
|
ctypes.c_int32.from_buffer(
|
|
player, OFFSETS[platform]["frame"]).value = 91
|
|
font = self.font()
|
|
heads = (ctypes.c_void_p * 1)()
|
|
first = (ctypes.c_uint8 * 0x70)()
|
|
alternate = (ctypes.c_uint8 * 0x70)()
|
|
heads[0] = ctypes.addressof(first)
|
|
ctypes.c_void_p.from_buffer(font, 0x40).value = ctypes.addressof(heads)
|
|
ctypes.c_void_p.from_buffer(first, 0x08).value = \
|
|
ctypes.addressof(alternate)
|
|
ctypes.c_float.from_buffer(first, 0x30).value = 100.0
|
|
ctypes.c_float.from_buffer(first, 0x34).value = 100.0
|
|
ctypes.c_float.from_buffer(alternate, 0x50).value = 1.0
|
|
ctypes.c_float.from_buffer(alternate, 0x54).value = 2.5
|
|
ctypes.c_float.from_buffer(alternate, 0x58).value = 3.5
|
|
(ctypes.c_float * 4).from_buffer(alternate, 0x20)[:] = \
|
|
(0.1, 0.2, 0.3, 0.4)
|
|
(ctypes.c_float * 4).from_buffer(alternate, 0x38)[:] = (1, 2, 3, 4)
|
|
ctypes.c_int16.from_buffer(alternate, 0x5C).value = 7
|
|
rgba = (ctypes.c_uint8 * 4)(1, 2, 3, 4)
|
|
|
|
lib.iggy_draw_char(player, font, 1.0, 0, 5, 6, rgba, None)
|
|
|
|
self.assertEqual(self.integer(lib, "shape_test_buffered_rect_calls"), 1,
|
|
platform)
|
|
self.assertEqual(ctypes.c_int32.from_buffer(first, 0x48).value, 0,
|
|
platform)
|
|
self.assertEqual(ctypes.c_int32.from_buffer(alternate, 0x48).value, 91,
|
|
platform)
|
|
self.assertEqual(ctypes.c_int32.from_buffer(
|
|
player, OFFSETS[platform]["shape_chars"]).value, 0, platform)
|
|
|
|
lib.shape_test_reset()
|
|
ctypes.c_void_p.from_buffer(first, 0x08).value = 0
|
|
ctypes.c_float.from_buffer(first, 0x50).value = 0.0
|
|
ctypes.c_float.from_buffer(first, 0x30).value = 0.1
|
|
ctypes.c_float.from_buffer(first, 0x34).value = 3.0
|
|
lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_buffered_rect_calls"), 0,
|
|
platform)
|
|
self.assertEqual(ctypes.c_int32.from_buffer(
|
|
player, OFFSETS[platform]["shape_chars"]).value, 1, platform)
|
|
|
|
ctypes.c_float.from_buffer(first, 0x50).value = 1.0
|
|
ctypes.c_float.from_buffer(first, 0x54).value = 4.0
|
|
ctypes.c_float.from_buffer(first, 0x58).value = 5.0
|
|
lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None)
|
|
ctypes.c_float.from_buffer(first, 0x54).value = 2.0
|
|
ctypes.c_float.from_buffer(first, 0x58).value = 2.5
|
|
lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_buffered_rect_calls"), 0,
|
|
platform)
|
|
|
|
def test_embedded_and_substituted_character_shapes(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
self.set_cache_limits(player, platform, 0.0)
|
|
font = self.font()
|
|
ctypes.c_int32.from_buffer(font, 0x18).value = 1
|
|
root = (ctypes.c_uint8 * 0x40)()
|
|
source = (ctypes.c_uint8 * 0x40)()
|
|
owner = ShapeOwner(section_count=1,
|
|
section_sources=ctypes.addressof(source))
|
|
ctypes.c_void_p.from_buffer(font, 0).value = ctypes.addressof(root)
|
|
ctypes.c_void_p.from_buffer(root, 0x30).value = ctypes.addressof(owner)
|
|
primitive = PackedPrimitive(vertex_format=5)
|
|
section = VertexBufferSection(ctypes.pointer(primitive), 1, 9, 0)
|
|
lib.shape_test_set_draw_result(None, 0x7171, ctypes.byref(section))
|
|
ctypes.c_int.in_dll(
|
|
lib, "shape_test_triangulate_allocated").value = 1
|
|
rgba = (ctypes.c_uint8 * 4)(255, 200, 100, 50)
|
|
|
|
lib.iggy_draw_char(player, font, 1.0, 0, 2, 3, rgba, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_triangulate_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_draw_batch_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_lowlevel_xform_calls"), 2,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_free_alloc_calls"), 1,
|
|
platform)
|
|
|
|
lib.shape_test_reset()
|
|
ctypes.c_int.in_dll(
|
|
lib, "shape_test_triangulate_null_result").value = 1
|
|
lib.iggy_draw_char(player, font, 1.0, 0, 2, 3, rgba, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_lowlevel_xform_calls"), 2,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_draw_batch_calls"), 0,
|
|
platform)
|
|
|
|
lib.shape_test_reset()
|
|
font = self.font()
|
|
ctypes.c_void_p.from_buffer(font, 0xC8).value = 1
|
|
ctypes.c_void_p.from_buffer(font, 0x50).value = 0xBEEF
|
|
table = (ctypes.c_void_p * 1)()
|
|
ctypes.c_void_p.from_buffer(font, 0x48).value = ctypes.addressof(table)
|
|
lib.shape_test_set_draw_result(None, 0x8181, ctypes.byref(section))
|
|
lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None)
|
|
self.assertNotEqual(table[0], None, platform)
|
|
allocated_owner = ShapeOwner.from_address(table[0])
|
|
self.assertEqual((allocated_owner.section_count,
|
|
allocated_owner.cache_policy,
|
|
allocated_owner.indirect_owner), (1, 1, 1), platform)
|
|
self.assertEqual(allocated_owner.allocator_owner, 0xBEEF, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_malloc_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_get_shape_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_free_shape_calls"), 1,
|
|
platform)
|
|
glyph_shape = ctypes.c_size_t.in_dll(
|
|
lib, "shape_test_glyph_shape_output").value
|
|
triangulate_source = ctypes.c_size_t.in_dll(
|
|
lib, "shape_test_triangulate_source").value
|
|
self.assertEqual(
|
|
triangulate_source - glyph_shape,
|
|
{"durango": 0x30, "orbis": 0x18,
|
|
"ps3": 0x68, "vita": 0x20}[platform], platform)
|
|
|
|
lib.shape_test_reset()
|
|
ctypes.c_int.in_dll(lib, "shape_test_triangulate_failed").value = 1
|
|
lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_triangulate_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_free_shape_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_lowlevel_xform_calls"), 0,
|
|
platform)
|
|
|
|
lib.shape_test_reset()
|
|
failed_table = (ctypes.c_void_p * 1)()
|
|
ctypes.c_void_p.from_buffer(font, 0x48).value = \
|
|
ctypes.addressof(failed_table)
|
|
ctypes.c_int.in_dll(lib, "shape_test_malloc_fail").value = 1
|
|
lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None)
|
|
self.assertIsNone(failed_table[0], platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_malloc_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_triangulate_calls"), 0,
|
|
platform)
|
|
|
|
lib.shape_test_reset()
|
|
missing = self.font()
|
|
frame = 1001 + tuple(self.libs).index(platform)
|
|
ctypes.c_int32.from_buffer(
|
|
player, OFFSETS[platform]["frame"]).value = frame
|
|
lib.iggy_draw_char(player, missing, 1.0, 0, 0, 0, rgba, None)
|
|
lib.iggy_draw_char(player, missing, 1.0, 0, 0, 0, rgba, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_send_error_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_last_error_code"), 0x194,
|
|
platform)
|
|
ctypes.c_int32.from_buffer(
|
|
player, OFFSETS[platform]["frame"]).value = frame + 1
|
|
lib.iggy_draw_char(player, missing, 1.0, 0, 0, 0, rgba, None)
|
|
self.assertEqual(self.integer(lib, "shape_test_send_error_calls"), 2,
|
|
platform)
|
|
|
|
def test_iggyexp_character_bitmap_and_vector_paths(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
self.set_cache_limits(player, platform)
|
|
lib.shape_test_install_exporter(player, OFFSETS[platform]["exporter"])
|
|
font = self.font()
|
|
heads = (ctypes.c_void_p * 1)()
|
|
record = (ctypes.c_uint8 * 0x70)()
|
|
heads[0] = ctypes.addressof(record)
|
|
ctypes.c_void_p.from_buffer(font, 0x40).value = ctypes.addressof(heads)
|
|
ctypes.c_float.from_buffer(record, 0x30).value = 2.0
|
|
ctypes.c_float.from_buffer(record, 0x34).value = 3.0
|
|
stats = ExpShapeStats(id=0x123456789ABCDEF0)
|
|
|
|
lib.iggy_iggyexp_char(player, None, 1.0, 0, ctypes.byref(stats))
|
|
ctypes.c_int.in_dll(lib, "shape_test_glyph_empty").value = 1
|
|
lib.iggy_iggyexp_char(player, font, 1.0, 0, ctypes.byref(stats))
|
|
ctypes.c_int.in_dll(lib, "shape_test_glyph_empty").value = 0
|
|
|
|
lib.iggy_iggyexp_char(player, font, 1.0, 0, ctypes.byref(stats))
|
|
self.assertEqual(stats.bitmap_count, 1, platform)
|
|
self.assertEqual(stats.bitmap_records[0], ctypes.addressof(record),
|
|
platform)
|
|
for index in range(1, 63):
|
|
stats.bitmap_records[index] = ctypes.addressof(record)
|
|
stats.bitmap_count = 63
|
|
lib.iggy_iggyexp_char(player, font, 1.0, 0, ctypes.byref(stats))
|
|
self.assertEqual(stats.bitmap_count, 0, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_export_calls"), 2,
|
|
platform)
|
|
|
|
lib.shape_test_reset()
|
|
font = self.font()
|
|
ctypes.c_int32.from_buffer(font, 0x18).value = 1
|
|
root = (ctypes.c_uint8 * 0x40)()
|
|
source = (ctypes.c_uint8 * 0x40)()
|
|
owner = ShapeOwner(section_count=1,
|
|
section_sources=ctypes.addressof(source))
|
|
ctypes.c_void_p.from_buffer(font, 0).value = ctypes.addressof(root)
|
|
ctypes.c_void_p.from_buffer(root, 0x30).value = ctypes.addressof(owner)
|
|
self.set_cache_limits(player, platform, 0.0)
|
|
ctypes.c_int.in_dll(lib, "shape_test_measure_result").value = 1
|
|
stats = ExpShapeStats(id=0xABCDEF)
|
|
lib.iggy_iggyexp_char(player, font, 1.0, 0, ctypes.byref(stats))
|
|
self.assertEqual(self.integer(lib, "shape_test_measure_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_export_calls"), 1,
|
|
platform)
|
|
self.assertEqual(stats.id, 0xABCDEF, platform)
|
|
self.assertEqual(stats.sections, 0, platform)
|
|
|
|
lib.shape_test_reset()
|
|
rootless = self.font()
|
|
ctypes.c_int32.from_buffer(rootless, 0x18).value = 1
|
|
stats = ExpShapeStats(id=55)
|
|
lib.iggy_iggyexp_char(
|
|
player, rootless, 1.0, 0, ctypes.byref(stats))
|
|
empty_root = (ctypes.c_uint8 * 0x40)()
|
|
ctypes.c_void_p.from_buffer(rootless, 0).value = \
|
|
ctypes.addressof(empty_root)
|
|
lib.iggy_iggyexp_char(
|
|
player, rootless, 1.0, 0, ctypes.byref(stats))
|
|
self.assertEqual(self.integer(lib, "shape_test_measure_calls"), 0,
|
|
platform)
|
|
|
|
no_table = self.font()
|
|
ctypes.c_void_p.from_buffer(no_table, 0xC8).value = 1
|
|
lib.iggy_iggyexp_char(
|
|
player, no_table, 1.0, 0, ctypes.byref(stats))
|
|
no_provider = self.font()
|
|
lib.iggy_iggyexp_char(
|
|
player, no_provider, 1.0, 0, ctypes.byref(stats))
|
|
self.assertEqual(self.integer(lib, "shape_test_measure_calls"), 0,
|
|
platform)
|
|
|
|
lib.shape_test_reset()
|
|
font = self.font()
|
|
ctypes.c_void_p.from_buffer(font, 0xC8).value = 1
|
|
table = (ctypes.c_void_p * 1)(ctypes.addressof(owner))
|
|
ctypes.c_void_p.from_buffer(font, 0x48).value = ctypes.addressof(table)
|
|
stats = ExpShapeStats(id=77)
|
|
lib.iggy_iggyexp_char(player, font, 1.0, 0, ctypes.byref(stats))
|
|
self.assertEqual(self.integer(lib, "shape_test_measure_calls"), 1,
|
|
platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_export_calls"), 0,
|
|
platform)
|
|
self.assertEqual(stats.id, 77, platform)
|
|
|
|
def test_draw_shape_failure_success_and_temporary_cleanup(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
shape = (ctypes.c_uint8 * 32)()
|
|
ctypes.c_int.in_dll(lib, "shape_test_triangulate_failed").value = 1
|
|
result = lib.iggy_draw_shape_raw(
|
|
player, shape, -2.0, None, None, None, None, 0, 0)
|
|
self.assertEqual(result, 0, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_free_alloc_calls"), 0)
|
|
|
|
lib.shape_test_reset()
|
|
result = lib.iggy_draw_shape_raw(
|
|
player, shape, -2.0, None, None, None, None, 0, 0)
|
|
self.assertEqual(result, 1, platform)
|
|
|
|
lib.shape_test_reset()
|
|
sections = (ctypes.c_uint8 * 0x40)()
|
|
fills = (ctypes.c_uint8 * 16)()
|
|
triangulation = (ctypes.c_uint8 * 0xB0)()
|
|
ctypes.c_int32.from_buffer(fills, 0).value = 2
|
|
ctypes.c_int16.from_buffer(shape, 8).value = 1
|
|
ctypes.c_void_p.from_buffer(shape, 24).value = ctypes.addressof(sections)
|
|
is_64 = ctypes.sizeof(ctypes.c_void_p) == 8
|
|
fill_offset = 0x20 if is_64 else 0x18
|
|
ctypes.c_void_p.from_buffer(sections, fill_offset).value = \
|
|
ctypes.addressof(fills)
|
|
sections[0x38 if is_64 else 0x24] = 1
|
|
lib.shape_test_set_draw_result(triangulation, 0, None)
|
|
ctypes.c_int.in_dll(lib, "shape_test_triangulate_allocated").value = 1
|
|
result = lib.iggy_draw_shape_raw(
|
|
player, shape, 1.0, None, None, None, None, 0, 0)
|
|
self.assertEqual(result, 1, platform)
|
|
self.assertEqual(ctypes.c_uint16.from_buffer(triangulation, 0x32).value,
|
|
9, platform)
|
|
self.assertEqual(ctypes.c_uint16.from_buffer(triangulation, 0x8A).value,
|
|
9, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_free_triangulation_calls"),
|
|
1, platform)
|
|
freed = (ctypes.c_size_t * 16).in_dll(lib, "shape_test_freed")
|
|
self.assertEqual(freed[0], ctypes.addressof(triangulation), platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_free_alloc_calls"), 2,
|
|
platform)
|
|
|
|
def test_shape_telemetry_begin_and_end_callbacks(self):
|
|
for platform, lib in self.libs.items():
|
|
player = self.player(platform)
|
|
shape = (ctypes.c_uint8 * 32)()
|
|
lib.shape_test_install_telemetry()
|
|
ctypes.c_int.in_dll(lib, "shape_test_triangulate_failed").value = 1
|
|
self.assertEqual(lib.iggy_draw_shape_raw(
|
|
player, shape, 0.0, None, None, None, None, 0, 0), 0, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_telemetry_begin_calls"),
|
|
1, platform)
|
|
self.assertEqual(self.integer(lib, "shape_test_telemetry_end_calls"),
|
|
1, platform)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|