feat(iggy-shim): M-A — game boots with Iggy DLL fully replaced

Open reimplementation of the Iggy flash-player C API (240+ symbols) as
iggy_shim_w64.dll. Object model: interned names, value-path resolution
over a Flash-like display/property tree, method-call dispatch hooks.
Scene identity via SWF byte fingerprinting (gen-scenes-tsv.py, 366
scenes) since the game passes a null config. Verified: client runs with
no RAD code loaded; scenes create/tick; game drives HUD+Intro methods.

patches/0002: upstream CMakeLists hard-set IGGY_LIBS; now overridable.
This commit is contained in:
2026-07-07 03:50:19 -05:00
parent f8a0cdb28c
commit 51897bce95
9 changed files with 1472 additions and 0 deletions

50
gen-scenes-tsv.py Normal file
View File

@@ -0,0 +1,50 @@
#!/usr/bin/env python3
"""Generate uiassets/scenes.tsv for the iggy-shim: fingerprints every SWF the
game may load and joins it with the extracted layout manifest metadata."""
import json
import os
import sys
import zlib
GAME = os.path.expanduser(
os.environ.get("GAME_DIR", "~/neoLegacy/build/windows64-clang-mac/Minecraft.Client"))
LAYOUT = os.path.expanduser(os.environ.get("LAYOUT_DIR", "~/neoLegacy-mac/ui-layout"))
OUT = os.path.join(os.path.expanduser(os.environ.get("OUT_DIR", GAME)), "uiassets")
rows = []
seen = set()
for root in (os.path.join(GAME, "Common/Media"), os.path.join(GAME, "Windows64Media/Media")):
for dirpath, _, files in os.walk(root):
for fn in files:
if not fn.endswith(".swf"):
continue
path = os.path.join(dirpath, fn)
name = fn[:-4]
data = open(path, "rb").read()
if data[:2] == b"MZ": # upstream's mislabeled PE files
continue
crc = zlib.crc32(data[:4096]) & 0xFFFFFFFF
key = (len(data), crc)
if key in seen:
continue
seen.add(key)
w, h, fps, doc = 1280, 720, 30.0, ""
manifest = os.path.join(LAYOUT, name + ".json")
if os.path.exists(manifest):
try:
m = json.load(open(manifest))
w, h, fps = int(m["width"]), int(m["height"]), float(m["fps"])
for exp in m.get("exports", {}):
if exp.startswith("fourj.documents."):
doc = exp
break
except Exception as e:
print(f"warn: bad manifest {name}: {e}", file=sys.stderr)
rows.append((name, len(data), crc, w, h, fps, doc))
os.makedirs(OUT, exist_ok=True)
with open(os.path.join(OUT, "scenes.tsv"), "w") as f:
f.write("# name\tsize\tcrc32(first4k,hex)\twidth\theight\tfps\tdocClass\n")
for name, size, crc, w, h, fps, doc in sorted(rows):
f.write(f"{name}\t{size}\t{crc:08x}\t{w}\t{h}\t{fps}\t{doc}\n")
print(f"wrote {len(rows)} scenes to {os.path.join(OUT, 'scenes.tsv')}")

25
iggy-shim/CMakeLists.txt Normal file
View File

@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.20)
project(iggy-shim LANGUAGES CXX)
# Path to the neoLegacy checkout (for the public Iggy headers we implement).
set(NEOLEGACY_DIR "$ENV{HOME}/neoLegacy" CACHE PATH "neoLegacy source tree")
set(IGGY_INCLUDE "${NEOLEGACY_DIR}/Minecraft.Client/Windows64/Iggy/include")
# Built as a DLL with __RADINDLL__ so RADEXPFUNC resolves to dllexport —
# the exact linking model the original iggy_w64.dll used. The game links our
# import lib (iggy_shim_w64.lib) instead of RAD's.
add_library(iggy_shim SHARED
src/iggy_api_core.cpp
src/iggy_api_values.cpp
src/scene_registry.cpp
)
target_include_directories(iggy_shim PRIVATE "${IGGY_INCLUDE}" src)
target_compile_features(iggy_shim PRIVATE cxx_std_17)
target_compile_definitions(iggy_shim PRIVATE __RADINDLL__)
if(MSVC OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(iggy_shim PRIVATE /MT /EHsc /W3)
endif()
set_target_properties(iggy_shim PROPERTIES OUTPUT_NAME "iggy_shim_w64" PREFIX "")

View File

@@ -0,0 +1,384 @@
// iggy-shim: core API surface — init/shutdown, global config, fonts, audio,
// libraries, player lifecycle, rendering entry points, gdraw helpers, and the
// perfmon/expruntime side libraries.
#include "iggy_object.hpp"
#include "iggy_player.hpp"
#include "scene_registry.hpp"
#include "iggy.h"
#include "iggyexpruntime.h"
#include "iggyperfmon.h"
#include <cstdarg>
#include <cstdio>
#include <cstring>
#undef IggyGDrawMalloc // iggy.h macro-redirects this to the Annotated variant
using namespace shim;
namespace shim {
Globals &globals() {
static Globals g;
return g;
}
NameTable &names() {
static NameTable t;
return t;
}
void debugLog(const char *fmt, ...) {
static FILE *f = nullptr;
if (!f) {
f = fopen("iggy_shim.log", "w");
if (!f) return;
}
va_list ap;
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);
fputc('\n', f);
fflush(f);
}
} // namespace shim
////////////////////////////////////////////////////////////
// Basic operations / global config
////////////////////////////////////////////////////////////
RADEXPFUNC void RADEXPLINK IggyInit(IggyAllocator *) {
shim::debugLog("IggyInit");
}
RADEXPFUNC void RADEXPLINK IggyShutdown(void) {}
RADEXPFUNC void RADEXPLINK IggyConfigureBool(IggyConfigureBoolName, rrbool) {}
RADEXPFUNC void RADEXPLINK IggyConfigureVersionedBehavior(IggyVersionedBehaviorName, IggyVersionNumber) {}
RADEXPFUNC void RADEXPLINK IggyUseTmLite(void *, IggyTelemetryAmount) {}
RADEXPFUNC void RADEXPLINK IggyUseTelemetry(void *, IggyTelemetryAmount) {}
RADEXPFUNC void RADEXPLINK IggySetLanguage(IggyLanguageCode) {}
////////////////////////////////////////////////////////////
// Translation callbacks (stored but unused for now: loc text arrives
// pre-translated through the setters the game uses)
////////////////////////////////////////////////////////////
RADEXPFUNC void RADEXPLINK IggySetLoadtimeTranslationFunction(Iggy_TranslateFunctionUTF16 *, void *, Iggy_TranslationFreeFunction *, void *) {}
RADEXPFUNC void RADEXPLINK IggySetLoadtimeTranslationFunctionUTF16(Iggy_TranslateFunctionUTF16 *, void *, Iggy_TranslationFreeFunction *, void *) {}
RADEXPFUNC void RADEXPLINK IggySetLoadtimeTranslationFunctionUTF8(Iggy_TranslateFunctionUTF8 *, void *, Iggy_TranslationFreeFunction *, void *) {}
RADEXPFUNC void RADEXPLINK IggySetRuntimeTranslationFunction(Iggy_TranslateFunctionUTF16 *, void *, Iggy_TranslationFreeFunction *, void *) {}
RADEXPFUNC void RADEXPLINK IggySetRuntimeTranslationFunctionUTF16(Iggy_TranslateFunctionUTF16 *, void *, Iggy_TranslationFreeFunction *, void *) {}
RADEXPFUNC void RADEXPLINK IggySetRuntimeTranslationFunctionUTF8(Iggy_TranslateFunctionUTF8 *, void *, Iggy_TranslationFreeFunction *, void *) {}
RADEXPFUNC void RADEXPLINK IggySetTextfieldTranslationFunctionUTF16(Iggy_TextfieldTranslateFunctionUTF16 *, void *, Iggy_TranslationFreeFunction *, void *) {}
RADEXPFUNC void RADEXPLINK IggySetTextfieldTranslationFunctionUTF8(Iggy_TextfieldTranslateFunctionUTF8 *, void *, Iggy_TranslationFreeFunction *, void *) {}
////////////////////////////////////////////////////////////
// Libraries & players
////////////////////////////////////////////////////////////
static std::string utf16ToUtf8(const IggyUTF16 *s) {
if (!s) return {};
std::u16string u16;
for (const IggyUTF16 *p = s; *p; ++p) u16.push_back((char16_t)*p);
return NameTable::toUtf8(u16);
}
RADEXPFUNC Iggy *RADEXPLINK IggyPlayerCreateFromFileAndPlay(char const *filename, IggyPlayerConfig const *) {
return sceneCreatePlayer(filename ? filename : "");
}
RADEXPFUNC Iggy *RADEXPLINK IggyPlayerCreateFromMemory(void const *data, U32 size, IggyPlayerConfig *config) {
// The game passes raw SWF bytes and a null config; scene identity comes
// from fingerprinting those bytes against the conversion manifest.
const char *fn = (config && config->filename) ? config->filename : "";
return sceneCreatePlayerFromData(data, size, fn);
}
RADEXPFUNC IggyLibrary RADEXPLINK IggyLibraryCreateFromMemory(char const *url, void const *, U32, IggyPlayerConfig *) {
auto &g = globals();
std::lock_guard<std::mutex> lock(g.mutex);
int h = g.nextLibraryHandle++;
g.libraries[h] = url ? url : "";
shim::debugLog("IggyLibraryCreateFromMemory url=%s -> %d", url ? url : "(null)", h);
return h;
}
RADEXPFUNC IggyLibrary RADEXPLINK IggyLibraryCreateFromMemoryUTF16(IggyUTF16 const *url, void const *data, U32 size, IggyPlayerConfig *config) {
std::string u8 = utf16ToUtf8(url);
return IggyLibraryCreateFromMemory(u8.c_str(), data, size, config);
}
RADEXPFUNC void RADEXPLINK IggyPlayerDestroy(Iggy *player) {
if (!player) return;
auto &g = globals();
{
std::lock_guard<std::mutex> lock(g.mutex);
g.players.erase(std::remove(g.players.begin(), g.players.end(), (shim::PlayerImpl *)player), g.players.end());
}
sceneDestroyPlayer(player);
}
RADEXPFUNC void RADEXPLINK IggyLibraryDestroy(IggyLibrary lib) {
auto &g = globals();
std::lock_guard<std::mutex> lock(g.mutex);
g.libraries.erase(lib);
}
RADEXPFUNC void RADEXPLINK IggySetWarningCallback(Iggy_WarningFunction *error, void *user) {
globals().warningFn = (void (*)(void *, Iggy *, int, const char *))error;
globals().warningUser = user;
}
RADEXPFUNC void RADEXPLINK IggySetTraceCallbackUTF8(Iggy_TraceFunctionUTF8 *, void *) {}
RADEXPFUNC void RADEXPLINK IggySetTraceCallbackUTF16(Iggy_TraceFunctionUTF16 *, void *) {}
RADEXPFUNC IggyProperties *RADEXPLINK IggyPlayerProperties(Iggy *player) {
static thread_local IggyProperties props;
props = {};
if (player) {
props.movie_width_in_pixels = player->movieW;
props.movie_height_in_pixels = player->movieH;
props.movie_frame_rate_current_in_fps = player->curFps;
props.movie_frame_rate_from_file_in_fps = player->fileFps;
props.frames_passed = player->framesPassed;
props.swf_major_version_number = 9;
props.time_passed_in_seconds = player->timePassed;
props.seconds_since_last_tick = player->lastTickSeconds;
props.seconds_per_drawn_frame = player->secondsPerDrawnFrame;
}
return &props;
}
RADEXPFUNC void *RADEXPLINK IggyPlayerGetUserdata(Iggy *player) { return player ? player->userdata : nullptr; }
RADEXPFUNC void RADEXPLINK IggyPlayerSetUserdata(Iggy *player, void *userdata) { if (player) player->userdata = userdata; }
RADEXPFUNC void RADEXPLINK IggyPlayerInitializeAndTickRS(Iggy *player) { scenePlayerTick(player, true); }
RADEXPFUNC rrbool RADEXPLINK IggyPlayerReadyToTick(Iggy *player) { return player && player->valid; }
RADEXPFUNC void RADEXPLINK IggyPlayerTickRS(Iggy *player) { scenePlayerTick(player, false); }
RADEXPFUNC void RADEXPLINK IggyPlayerPause(Iggy *player, IggyAudioPauseMode) { if (player) player->paused = true; }
RADEXPFUNC void RADEXPLINK IggyPlayerPlay(Iggy *player) { if (player) player->paused = false; }
RADEXPFUNC void RADEXPLINK IggyPlayerSetFrameRate(Iggy *player, F32 fps) { if (player) player->curFps = fps; }
RADEXPFUNC void RADEXPLINK IggyPlayerGotoFrameRS(Iggy *f, S32 frame, rrbool) {
if (f && f->root) f->root->currentFrame = frame;
}
RADEXPFUNC rrbool RADEXPLINK IggyPlayerGetValid(Iggy *f) { return f && f->valid; }
RADEXPFUNC void RADEXPLINK IggyInstallPerfmon(void *) {}
RADEXPFUNC void RADEXPLINK IggyUseExplorer(Iggy *, void *) {}
RADEXPFUNC void RADEXPLINK IggyPlayerSendFrameToExplorer(Iggy *) {}
////////////////////////////////////////////////////////////
// Fonts
////////////////////////////////////////////////////////////
RADEXPFUNC void RADEXPLINK IggySetInstalledFontMaxCount(S32) {}
RADEXPFUNC void RADEXPLINK IggySetIndirectFontMaxCount(S32) {}
RADEXPFUNC void RADEXPLINK IggyFontInstallTruetypeUTF8(const void *ttf, S32 ttcIndex, const char *fontname, S32 namelen, U32 flags) {
if (!fontname) return;
std::u16string name = NameTable::fromUtf8(std::string(fontname, fontname + (namelen > 0 ? namelen : (S32)strlen(fontname))));
auto &g = globals();
std::lock_guard<std::mutex> lock(g.mutex);
g.fonts[name] = {ttf, ttcIndex, flags};
shim::debugLog("FontInstall %s", NameTable::toUtf8(name).c_str());
sceneOnFontInstalled(name, ttf, ttcIndex, flags);
}
RADEXPFUNC void RADEXPLINK IggyFontInstallTruetypeUTF16(const void *ttf, S32 ttcIndex, const U16 *fontname, S32 namelen, U32 flags) {
std::u16string name;
for (S32 i = 0; i < namelen && fontname && fontname[i]; i++) name.push_back((char16_t)fontname[i]);
IggyFontInstallTruetypeUTF8(ttf, ttcIndex, NameTable::toUtf8(name).c_str(), -1, flags);
}
RADEXPFUNC void RADEXPLINK IggyFontInstallTruetypeFallbackCodepointUTF8(const char *, S32, U32, S32) {}
RADEXPFUNC void RADEXPLINK IggyFontInstallTruetypeFallbackCodepointUTF16(const U16 *, S32, U32, S32) {}
RADEXPFUNC void RADEXPLINK IggyFontInstallVectorUTF8(const IggyVectorFontProvider *, const char *, S32, U32) {}
RADEXPFUNC void RADEXPLINK IggyFontInstallVectorUTF16(const IggyVectorFontProvider *, const U16 *, S32, U32) {}
RADEXPFUNC void RADEXPLINK IggyFontInstallBitmapUTF8(const IggyBitmapFontProvider *, const char *, S32, U32) {}
RADEXPFUNC void RADEXPLINK IggyFontInstallBitmapUTF16(const IggyBitmapFontProvider *, const U16 *, S32, U32) {}
RADEXPFUNC void RADEXPLINK IggyFontInstallBitmapOverrideUTF8(const IggyBitmapFontOverride *, const char *, S32, U32) {}
RADEXPFUNC void RADEXPLINK IggyFontInstallBitmapOverrideUTF16(const IggyBitmapFontOverride *, const U16 *, S32, U32) {}
RADEXPFUNC void RADEXPLINK IggyFontRemoveUTF8(const char *, S32, U32) {}
RADEXPFUNC void RADEXPLINK IggyFontRemoveUTF16(const U16 *, S32, U32) {}
RADEXPFUNC void RADEXPLINK IggyFontSetIndirectUTF8(const char *req, S32 reqlen, U32, const char *res, S32 reslen, U32) {
if (!req || !res) return;
std::string reqs(req, req + (reqlen > 0 ? reqlen : (S32)strlen(req)));
std::string ress(res, res + (reslen > 0 ? reslen : (S32)strlen(res)));
auto &g = globals();
std::lock_guard<std::mutex> lock(g.mutex);
g.fontIndirects[NameTable::fromUtf8(reqs)] = NameTable::fromUtf8(ress);
}
RADEXPFUNC void RADEXPLINK IggyFontSetIndirectUTF16(const U16 *req, S32 reqlen, U32 rf, const U16 *res, S32 reslen, U32 resf) {
std::u16string r, s;
for (S32 i = 0; i < reqlen && req && req[i]; i++) r.push_back((char16_t)req[i]);
for (S32 i = 0; i < reslen && res && res[i]; i++) s.push_back((char16_t)res[i]);
IggyFontSetIndirectUTF8(NameTable::toUtf8(r).c_str(), -1, rf, NameTable::toUtf8(s).c_str(), -1, resf);
}
RADEXPFUNC void RADEXPLINK IggyFontSetFallbackFontUTF8(const char *, S32, U32) {}
RADEXPFUNC void RADEXPLINK IggyFontSetFallbackFontUTF16(const U16 *, S32, U32) {}
RADEXPFUNC void RADEXPLINK IggyFlushInstalledFonts(void) {}
RADEXPFUNC void RADEXPLINK IggySetFontCachingCalculationBuffer(S32, void *, S32) {}
////////////////////////////////////////////////////////////
// Audio (the game routes all real audio through its own SoundEngine/miniaudio;
// Iggy audio was only for Flash-embedded sounds, which the scenes don't use)
////////////////////////////////////////////////////////////
RADEXPFUNC void RADEXPLINK IggyAudioSetDriver(IGGYSND_OPEN_FUNC, U32) {}
RADEXPFUNC void RADEXPLINK IggyAudioUseDirectSound(void) {}
RADEXPFUNC void RADEXPLINK IggyAudioUseWaveOut(void) {}
RADEXPFUNC void RADEXPLINK IggyAudioUseXAudio2(void) {}
RADEXPFUNC void RADEXPLINK IggyAudioUseLibAudio(void) {}
RADEXPFUNC void RADEXPLINK IggyAudioUseAX(void) {}
RADEXPFUNC void RADEXPLINK IggyAudioUseCoreAudio(void) {}
RADEXPFUNC void RADEXPLINK IggyAudioUseDefault(void) {}
RADEXPFUNC void RADEXPLINK IggyAudioInstallMP3Decoder(void) {}
RADEXPFUNC void RADEXPLINK IggySetDLLDirectory(char *) {}
RADEXPFUNC void RADEXPLINK IggySetDLLDirectoryW(wchar_t *) {}
RADEXPFUNC rrbool RADEXPLINK IggyAudioSetMaxBufferTime(S32) { return 1; }
RADEXPFUNC void RADEXPLINK IggyAudioSetLatency(S32) {}
RADEXPFUNC void RADEXPLINK IggyPlayerSetAudioVolume(Iggy *, F32) {}
RADEXPFUNC void RADEXPLINK IggyPlayerSetAudioDevice(Iggy *, S32) {}
////////////////////////////////////////////////////////////
// Rendering configuration + draw entry points
////////////////////////////////////////////////////////////
RADEXPFUNC void RADEXPLINK IggySetCustomDrawCallback(Iggy_CustomDrawCallback *cb, void *user) {
globals().customDrawFn = (void (*)(void *, Iggy *, IggyCustomDrawCallbackRegion *))cb;
globals().customDrawUser = user;
}
RADEXPFUNC void RADEXPLINK IggySetTextureSubstitutionCallbacks(Iggy_TextureSubstitutionCreateCallback *create, Iggy_TextureSubstitutionDestroyCallback *destroy, void *user) {
globals().texSubCreate = (GDrawTexture * (*)(void *, char16_t *, int32_t *, int32_t *, void **)) create;
globals().texSubDestroy = (void (*)(void *, void *, GDrawTexture *))destroy;
globals().texSubUser = user;
}
RADEXPFUNC void RADEXPLINK IggySetTextureSubstitutionCallbacksUTF8(Iggy_TextureSubstitutionCreateCallbackUTF8 *, Iggy_TextureSubstitutionDestroyCallback *, void *) {}
RADEXPFUNC void RADEXPLINK IggyTextureSubstitutionFlush(GDrawTexture *, IggyTextureSubstitutionFlushMode) {}
RADEXPFUNC void RADEXPLINK IggyTextureSubstitutionFlushAll(IggyTextureSubstitutionFlushMode) {}
RADEXPFUNC void RADEXPLINK IggySetGDraw(GDrawFunctions *gdraw) {
globals().gdraw = gdraw;
sceneOnGDrawSet(gdraw);
}
RADEXPFUNC void RADEXPLINK IggyPlayerGetBackgroundColor(Iggy *, F32 output_color[3]) {
if (output_color) output_color[0] = output_color[1] = output_color[2] = 0.f;
}
RADEXPFUNC void RADEXPLINK IggyPlayerSetDisplaySize(Iggy *f, S32 w, S32 h) {
if (f) { f->displayW = w; f->displayH = h; }
}
RADEXPFUNC void RADEXPLINK IggyPlayerSetPixelShape(Iggy *, F32, F32) {}
RADEXPFUNC void RADEXPLINK IggyPlayerSetStageRotation(Iggy *, Iggy90DegreeRotation) {}
RADEXPFUNC void RADEXPLINK IggyPlayerDraw(Iggy *f) { scenePlayerDraw(f); }
RADEXPFUNC void RADEXPLINK IggyPlayerSetStageSize(Iggy *f, S32 w, S32 h) {
if (f) { f->movieW = w; f->movieH = h; }
}
RADEXPFUNC void RADEXPLINK IggyPlayerSetFaux3DStage(Iggy *, F32 *, F32 *, F32 *, F32 *, F32) {}
RADEXPFUNC void RADEXPLINK IggyPlayerForceMipmaps(Iggy *, rrbool) {}
RADEXPFUNC void RADEXPLINK IggyPlayerDrawTile(Iggy *, S32, S32, S32, S32, S32) {}
RADEXPFUNC void RADEXPLINK IggyPlayerDrawTilesStart(Iggy *) {}
RADEXPFUNC void RADEXPLINK IggyPlayerDrawTilesEnd(Iggy *) {}
RADEXPFUNC void RADEXPLINK IggyPlayerSetRootTransform(Iggy *, F32 *, F32, F32) {}
RADEXPFUNC void RADEXPLINK IggyPlayerFlushAll(Iggy *) {}
RADEXPFUNC void RADEXPLINK IggyLibraryFlushAll(IggyLibrary) {}
RADEXPFUNC void RADEXPLINK IggySetTextCursorPixelWidth(S32) {}
RADEXPFUNC void RADEXPLINK IggyForceBitmapSmoothing(rrbool) {}
RADEXPFUNC void RADEXPLINK IggyFastTextFilterEffects(rrbool) {}
RADEXPFUNC void RADEXPLINK IggyPlayerSetAntialiasing(Iggy *, IggyAntialiasing) {}
RADEXPFUNC void RADEXPLINK IggyPlayerSetBitmapFontCaching(Iggy *, S32, S32, S32, S32) {}
RADEXPFUNC IggyGeneric *RADEXPLINK IggyPlayerGetGeneric(Iggy *) { return nullptr; }
RADEXPFUNC IggyGeneric *RADEXPLINK IggyLibraryGetGeneric(IggyLibrary) { return nullptr; }
RADEXPFUNC void RADEXPLINK IggyGenericInstallResourceFile(IggyGeneric *, void *, S32, rrbool *can_free_now) {
if (can_free_now) *can_free_now = 1;
}
RADEXPFUNC IggyTextureResourceMetadata *RADEXPLINK IggyGenericGetTextureResourceMetadata(IggyGeneric *) { return nullptr; }
RADEXPFUNC void RADEXPLINK IggyGenericSetTextureFromResource(IggyGeneric *, U16, GDrawTexture *) {}
////////////////////////////////////////////////////////////
// GC / debug
////////////////////////////////////////////////////////////
RADEXPFUNC void RADEXPLINK IggyPlayerGarbageCollect(Iggy *, S32) {}
RADEXPFUNC void RADEXPLINK IggyPlayerConfigureGCBehavior(Iggy *, Iggy_GarbageCollectionCallback *, IggyGarbageCollectorControl *) {}
RADEXPFUNC void RADEXPLINK IggyPlayerQueryGCSizes(Iggy *, IggyPlayerGCSizes *sizes) {
if (sizes) memset(sizes, 0, sizeof(*sizes));
}
RADEXPFUNC void RADEXPLINK IggyPlayerDebugEnableFilters(Iggy *, rrbool) {}
RADEXPFUNC void RADEXPLINK IggyPlayerDebugSetTime(Iggy *, F64) {}
RADEXPFUNC void RADEXPLINK IggyPlayerDebugBatchStartFrame(void) {}
RADEXPFUNC void RADEXPLINK IggyPlayerDebugBatchInit(void) {}
RADEXPFUNC void RADEXPLINK IggyPlayerDebugBatchMove(S32) {}
RADEXPFUNC void RADEXPLINK IggyPlayerDebugBatchSplit(void) {}
RADEXPFUNC void RADEXPLINK IggyPlayerDebugBatchChooseEnd(S32) {}
RADEXPFUNC void RADEXPLINK IggyPlayerDebugUpdateReadyToTickWithFakeRender(Iggy *) {}
RADEXPFUNC void RADEXPLINK IggyDebugBreakOnAS3Exception(void) {}
RADEXPFUNC rrbool RADEXPLINK IggyDebugGetMemoryUseInfo(Iggy *, IggyLibrary, char const *, S32, S32, IggyMemoryUseInfo *) { return 0; }
RADEXPFUNC void RADEXPLINK IggyDebugSetLeakResultCallback(IggyLeakResultCallback *) {}
RADEXPFUNC S32 RADEXPLINK IggyDebugGetNumValueRef(Iggy *) { return 0; }
RADEXPFUNC void RADEXPLINK IggySetValueRefLimit(Iggy *, S32) {}
RADEXPFUNC void RADEXPLINK iggy_sync_check_todisk(char *, U32) {}
RADEXPFUNC void RADEXPLINK iggy_sync_check_fromdisk(char *, U32) {}
RADEXPFUNC void RADEXPLINK iggy_sync_check_end(void) {}
////////////////////////////////////////////////////////////
// GDraw helper accessors
////////////////////////////////////////////////////////////
RADEXPFUNC void *RADEXPLINK IggyGDrawMallocAnnotated(SINTa size, const char *, int) { return malloc((size_t)size); }
RADEXPFUNC void *RADEXPLINK IggyGDrawMalloc(SINTa size) { return malloc((size_t)size); }
RADEXPFUNC void RADEXPLINK IggyGDrawFree(void *ptr) { free(ptr); }
RADEXPFUNC void RADEXPLINK IggyGDrawSendWarning(Iggy *f, char const *message, ...) {
char buf[1024];
va_list ap;
va_start(ap, message);
vsnprintf(buf, sizeof(buf), message, ap);
va_end(ap);
shim::debugLog("GDrawWarning: %s", buf);
auto &g = globals();
if (g.warningFn) g.warningFn(g.warningUser, f, IGGY_RESULT_Warning_GDraw, buf);
}
RADEXPFUNC void RADEXPLINK IggyWaitOnFence(void *, U32) {}
RADEXPFUNC void RADEXPLINK IggyDiscardVertexBufferCallback(void *, void *) {}
////////////////////////////////////////////////////////////
// IME (Windows-only surface, unused by the PNG scenes)
////////////////////////////////////////////////////////////
RADEXPFUNC void RADEXPLINK IggyPlayerSetIMEFontUTF8(Iggy *, const char *, S32) {}
RADEXPFUNC void RADEXPLINK IggyPlayerSetIMEFontUTF16(Iggy *, const IggyUTF16 *, S32) {}
RADEXPFUNC void RADEXPLINK IggyIMEWin32SetCompositionState(Iggy *, IggyIMECompostitionStringState *) {}
RADEXPFUNC void RADEXPLINK IggyIMEGetTextExtents(Iggy *, U32 *pdw, U32 *pdh, const IggyUTF16 *, U32) {
if (pdw) *pdw = 0;
if (pdh) *pdh = 0;
}
RADEXPFUNC void RADEXPLINK IggyIMEDrawString(Iggy *, S32, S32, const IggyUTF16 *, U32, const U8 *) {}
RADEXPFUNC void RADEXPLINK IggyIMEWin32GetCandidatePosition(Iggy *, F32 *pdx, F32 *pdy, F32 *pdh) {
if (pdx) *pdx = 0;
if (pdy) *pdy = 0;
if (pdh) *pdh = 0;
}
RADEXPFUNC void *RADEXPLINK IggyIMEGetFocusedTextfield(Iggy *) { return nullptr; }
RADEXPFUNC void RADEXPLINK IggyIMEDrawRect(S32, S32, S32, S32, const U8 *) {}
////////////////////////////////////////////////////////////
// iggyperfmon / iggyexpruntime side libraries
////////////////////////////////////////////////////////////
RADEXPFUNC HIGGYPERFMON RADEXPLINK IggyPerfmonCreate(iggyperfmon_malloc *, iggyperfmon_free *, void *) { return nullptr; }
RADEXPFUNC void RADEXPLINK IggyPerfmonTickAndDraw(HIGGYPERFMON, GDrawFunctions *, const IggyPerfmonPad *, int, int, int, int) {}
RADEXPFUNC void RADEXPLINK IggyPerfmonDestroy(HIGGYPERFMON, GDrawFunctions *) {}
RADEXPFUNC HIGGYEXP RADEXPLINK IggyExpCreate(char *, S32, void *, S32) { return nullptr; }
RADEXPFUNC void RADEXPLINK IggyExpDestroy(HIGGYEXP) {}
RADEXPFUNC rrbool RADEXPLINK IggyExpCheckValidity(HIGGYEXP) { return 0; }

View File

@@ -0,0 +1,429 @@
// iggy-shim: value paths, property get/set, fast names, method calls,
// value refs, input events, and focus enumeration.
#include "iggy_object.hpp"
#include "iggy_player.hpp"
#include "scene_registry.hpp"
#include "iggy.h"
#include <cstring>
using namespace shim;
namespace shim {
void debugLog(const char *fmt, ...);
}
////////////////////////////////////////////////////////////
// Path plumbing
//
// IggyValuePath is a public struct {f, parent, name, ref, index, type}. The
// game builds chains of these (usually rooted at IggyPlayerRootPath) and
// passes a leaf + optional extra sub_name to every get/set. We resolve a path
// by walking to the root, then descending by interned names / array indices.
////////////////////////////////////////////////////////////
namespace {
// path->type values we use; the real Iggy's are opaque, only it reads them.
enum PathType { PATH_ROOT = 0, PATH_NAME = 1, PATH_INDEX = 2, PATH_REF = 3 };
ObjectPtr resolveChain(IggyValuePath *path, bool vivify);
ObjectPtr resolveStep(const ObjectPtr &base, IggyValuePath *p, bool vivify) {
if (!base) return nullptr;
switch (p->type) {
case PATH_NAME: {
const std::u16string *n = names().lookup(p->name);
if (!n) return nullptr;
return vivify ? base->ensureChild(*n) : base->childByName(*n);
}
case PATH_INDEX: {
if (p->index < 0) return nullptr;
if ((size_t)p->index >= base->array.size()) {
if (!vivify) return nullptr;
base->isArray = true;
base->array.resize(p->index + 1);
}
Value &slot = base->array[p->index];
if (slot.type != Value::Type::Object) {
if (!vivify) return nullptr;
auto child = std::make_shared<IggyObjectNode>();
child->parent = base;
slot = Value::object(child);
}
return slot.obj;
}
case PATH_REF:
return p->ref ? ((IggyObjectNode *)p->ref)->shared_from_this() : nullptr;
default:
return nullptr;
}
}
ObjectPtr resolveChain(IggyValuePath *path, bool vivify) {
if (!path) return nullptr;
if (path->type == PATH_ROOT || !path->parent) {
if (path->type == PATH_REF && path->ref)
return ((IggyObjectNode *)path->ref)->shared_from_this();
return (path->f && path->f->root) ? path->f->root : nullptr;
}
ObjectPtr parent = resolveChain(path->parent, vivify);
if (!parent) return nullptr;
return resolveStep(parent, path, vivify);
}
// Resolve the (path, sub_name/sub_name_utf8) addressing every accessor uses.
// If subName resolves to a property we return the owning object + prop name;
// with no sub name, the path's leaf itself is the property on ITS parent —
// but Iggy semantics are simpler: accessors always address a property named
// by sub_name (fast or utf8) ON the object identified by `var`.
struct PropAddr {
ObjectPtr obj;
std::u16string prop;
bool ok = false;
};
PropAddr addrOf(IggyValuePath *var, IggyName sub_name, const char *sub_utf8, bool vivify) {
PropAddr a;
a.obj = resolveChain(var, vivify);
if (!a.obj) return a;
if (sub_name) {
const std::u16string *n = names().lookup(sub_name);
if (!n) return a;
a.prop = *n;
} else if (sub_utf8) {
a.prop = NameTable::fromUtf8(sub_utf8);
} else {
return a; // no property name → invalid for get/set use
}
a.ok = true;
return a;
}
void writeString16(const std::u16string &s, S32 maxLen, IggyUTF16 *out, S32 *outLen) {
S32 n = (S32)s.size();
if (n > maxLen - 1) n = maxLen - 1;
if (out && maxLen > 0) {
for (S32 i = 0; i < n; i++) out[i] = (IggyUTF16)s[i];
out[n] = 0;
}
if (outLen) *outLen = n;
}
} // namespace
////////////////////////////////////////////////////////////
// AS3 external-function callback registration (scene controllers invoke
// these to deliver handlePress/handleFocusChange/... back to the game)
////////////////////////////////////////////////////////////
RADEXPFUNC void RADEXPLINK IggySetAS3ExternalFunctionCallbackUTF8(Iggy_AS3ExternalFunctionUTF8 *, void *) {}
RADEXPFUNC void RADEXPLINK IggySetAS3ExternalFunctionCallbackUTF16(Iggy_AS3ExternalFunctionUTF16 *fn, void *user) {
globals().externalFn16 = (bool (*)(void *, Iggy *, IggyExternalFunctionCallUTF16 *))fn;
globals().externalFnUser16 = user;
}
////////////////////////////////////////////////////////////
// Fast names & root paths
////////////////////////////////////////////////////////////
RADEXPFUNC IggyName RADEXPLINK IggyPlayerCreateFastName(Iggy *, IggyUTF16 const *name, S32 len) {
std::u16string s;
for (S32 i = 0; (len < 0 || i < len) && name && name[i]; i++) s.push_back((char16_t)name[i]);
return (IggyName)names().intern(s);
}
RADEXPFUNC IggyName RADEXPLINK IggyPlayerCreateFastNameUTF8(Iggy *, char const *name, S32 len) {
std::string s(name, name + (len >= 0 ? len : (S32)strlen(name)));
return (IggyName)names().intern(NameTable::fromUtf8(s));
}
RADEXPFUNC IggyValuePath *RADEXPLINK IggyPlayerRootPath(Iggy *f) {
if (!f) return nullptr;
if (!f->rootPath) {
f->rootPath = new IggyValuePath{};
f->rootPath->f = f;
f->rootPath->parent = nullptr;
f->rootPath->type = PATH_ROOT;
}
return f->rootPath;
}
RADEXPFUNC IggyValuePath *RADEXPLINK IggyPlayerCallbackResultPath(Iggy *f) {
if (!f) return nullptr;
if (!f->cbResultPath) {
// a dedicated object holding the "callback result" property space
auto obj = std::make_shared<IggyObjectNode>();
obj->name = u"__callback_result__";
f->root->props[u"__callback_result__"] = Value::object(obj);
f->cbResultPath = new IggyValuePath{};
f->cbResultPath->f = f;
f->cbResultPath->parent = nullptr;
f->cbResultPath->type = PATH_REF;
f->cbResultPath->ref = obj.get();
}
return f->cbResultPath;
}
RADEXPFUNC rrbool RADEXPLINK IggyValuePathMakeNameRef(IggyValuePath *result, IggyValuePath *parent, char const *text_utf8) {
if (!result || !parent || !text_utf8) return 0;
result->f = parent->f;
result->parent = parent;
result->name = (IggyName)names().intern(NameTable::fromUtf8(text_utf8));
result->ref = nullptr;
result->index = -1;
result->type = PATH_NAME;
return 1;
}
RADEXPFUNC void RADEXPLINK IggyValuePathMakeNameRefFast(IggyValuePath *result, IggyValuePath *parent, IggyName name) {
if (!result || !parent) return;
result->f = parent->f;
result->parent = parent;
result->name = name;
result->ref = nullptr;
result->index = -1;
result->type = PATH_NAME;
}
RADEXPFUNC void RADEXPLINK IggyValuePathMakeArrayRef(IggyValuePath *result, IggyValuePath *array_path, int array_index) {
if (!result || !array_path) return;
result->f = array_path->f;
result->parent = array_path;
result->name = 0;
result->ref = nullptr;
result->index = array_index;
result->type = PATH_INDEX;
}
RADEXPFUNC void RADEXPLINK IggyValuePathFromRef(IggyValuePath *result, Iggy *iggy, IggyValueRef ref) {
if (!result) return;
result->f = iggy;
result->parent = nullptr;
result->name = 0;
result->ref = ref;
result->index = -1;
result->type = PATH_REF;
}
RADEXPFUNC void RADEXPLINK IggyValuePathSetParent(IggyValuePath *result, IggyValuePath *new_parent) {
if (result) result->parent = new_parent;
}
RADEXPFUNC void RADEXPLINK IggyValuePathSetArrayIndex(IggyValuePath *result, int new_index) {
if (result) { result->index = new_index; result->type = PATH_INDEX; }
}
RADEXPFUNC void RADEXPLINK IggyValuePathSetName(IggyValuePath *result, IggyName name) {
if (result) { result->name = name; result->type = PATH_NAME; }
}
////////////////////////////////////////////////////////////
// Value refs
////////////////////////////////////////////////////////////
RADEXPFUNC rrbool RADEXPLINK IggyValueRefCheck(IggyValueRef ref) { return ref != nullptr; }
RADEXPFUNC void RADEXPLINK IggyValueRefFree(Iggy *, IggyValueRef) {}
RADEXPFUNC IggyValueRef RADEXPLINK IggyValueRefFromPath(IggyValuePath *var, IggyValueRefType) {
ObjectPtr o = resolveChain(var, true);
return o.get();
}
RADEXPFUNC rrbool RADEXPLINK IggyIsValueRefSameObjectAsTempRef(IggyValueRef value_ref, IggyTempRef temp_ref) {
return value_ref == (void *)temp_ref;
}
RADEXPFUNC rrbool RADEXPLINK IggyIsValueRefSameObjectAsValuePath(IggyValueRef value_ref, IggyValuePath *path, IggyName sub_name, char const *sub_name_utf8) {
PropAddr a = addrOf(path, sub_name, sub_name_utf8, false);
if (!a.ok) {
ObjectPtr o = resolveChain(path, false);
return o.get() == value_ref;
}
Value v = a.obj->getProp(a.prop);
return v.type == Value::Type::Object && v.obj.get() == value_ref;
}
RADEXPFUNC IggyValueRef RADEXPLINK IggyValueRefCreateArray(Iggy *f, S32 num_slots) {
auto o = std::make_shared<IggyObjectNode>();
o->isArray = true;
o->array.resize(num_slots > 0 ? num_slots : 0);
// keep alive by anchoring under root's hidden refs bucket
if (f && f->root) f->root->children.push_back(o);
return o.get();
}
RADEXPFUNC IggyValueRef RADEXPLINK IggyValueRefCreateEmptyObject(Iggy *f) {
auto o = std::make_shared<IggyObjectNode>();
if (f && f->root) f->root->children.push_back(o);
return o.get();
}
RADEXPFUNC IggyValueRef RADEXPLINK IggyValueRefFromTempRef(Iggy *, IggyTempRef temp_ref, IggyValueRefType) {
return (IggyValueRef)temp_ref;
}
////////////////////////////////////////////////////////////
// Get / Set
////////////////////////////////////////////////////////////
RADEXPFUNC IggyResult RADEXPLINK IggyValueGetTypeRS(IggyValuePath *var, IggyName sub_name, char const *sub_utf8, IggyDatatype *result) {
PropAddr a = addrOf(var, sub_name, sub_utf8, false);
if (!result) return IGGY_RESULT_Error_InvalidArgument;
*result = IGGY_DATATYPE_undefined;
if (!a.ok) return IGGY_RESULT_Error_ValuePath;
Value v = a.obj->getProp(a.prop);
switch (v.type) {
case Value::Type::Boolean: *result = IGGY_DATATYPE_boolean; break;
case Value::Type::Number: *result = IGGY_DATATYPE_number; break;
case Value::Type::String: *result = IGGY_DATATYPE_string_UTF16; break;
case Value::Type::Object: *result = v.obj && v.obj->isArray ? IGGY_DATATYPE_array : IGGY_DATATYPE_object; break;
case Value::Type::Null: *result = IGGY_DATATYPE_null; break;
default: *result = IGGY_DATATYPE_undefined; break;
}
return IGGY_RESULT_SUCCESS;
}
#define GET_NUMERIC(NAME, TYPE) \
RADEXPFUNC IggyResult RADEXPLINK NAME(IggyValuePath *var, IggyName sub_name, char const *sub_utf8, TYPE *result) { \
PropAddr a = addrOf(var, sub_name, sub_utf8, false); \
if (!a.ok || !result) return IGGY_RESULT_Error_ValuePath; \
*result = (TYPE)a.obj->getProp(a.prop).asNumber(); \
return IGGY_RESULT_SUCCESS; \
}
GET_NUMERIC(IggyValueGetF64RS, F64)
GET_NUMERIC(IggyValueGetF32RS, F32)
GET_NUMERIC(IggyValueGetS32RS, S32)
GET_NUMERIC(IggyValueGetU32RS, U32)
RADEXPFUNC IggyResult RADEXPLINK IggyValueGetStringUTF16RS(IggyValuePath *var, IggyName sub_name, char const *sub_utf8, S32 max_result_len, IggyUTF16 *out, S32 *outLen) {
PropAddr a = addrOf(var, sub_name, sub_utf8, false);
if (!a.ok) return IGGY_RESULT_Error_ValuePath;
writeString16(a.obj->getProp(a.prop).asString(), max_result_len, out, outLen);
return IGGY_RESULT_SUCCESS;
}
RADEXPFUNC IggyResult RADEXPLINK IggyValueGetStringUTF8RS(IggyValuePath *var, IggyName sub_name, char const *sub_utf8, S32 max_result_len, char *out, S32 *outLen) {
PropAddr a = addrOf(var, sub_name, sub_utf8, false);
if (!a.ok) return IGGY_RESULT_Error_ValuePath;
std::string s = NameTable::toUtf8(a.obj->getProp(a.prop).asString());
S32 n = (S32)s.size();
if (n > max_result_len - 1) n = max_result_len - 1;
if (out && max_result_len > 0) { memcpy(out, s.data(), n); out[n] = 0; }
if (outLen) *outLen = n;
return IGGY_RESULT_SUCCESS;
}
RADEXPFUNC IggyResult RADEXPLINK IggyValueGetBooleanRS(IggyValuePath *var, IggyName sub_name, char const *sub_utf8, rrbool *result) {
PropAddr a = addrOf(var, sub_name, sub_utf8, false);
if (!a.ok || !result) return IGGY_RESULT_Error_ValuePath;
*result = a.obj->getProp(a.prop).asBool() ? 1 : 0;
return IGGY_RESULT_SUCCESS;
}
RADEXPFUNC IggyResult RADEXPLINK IggyValueGetArrayLengthRS(IggyValuePath *var, IggyName sub_name, char const *sub_utf8, S32 *result) {
PropAddr a = addrOf(var, sub_name, sub_utf8, false);
if (!a.ok || !result) return IGGY_RESULT_Error_ValuePath;
Value v = a.obj->getProp(a.prop);
*result = (v.type == Value::Type::Object && v.obj) ? (S32)v.obj->array.size() : 0;
return IGGY_RESULT_SUCCESS;
}
#define SET_VALUE(NAME, TYPE, MAKE) \
RADEXPFUNC rrbool RADEXPLINK NAME(IggyValuePath *var, IggyName sub_name, char const *sub_utf8, TYPE value) { \
PropAddr a = addrOf(var, sub_name, sub_utf8, true); \
if (!a.ok) return 0; \
a.obj->setProp(a.prop, MAKE); \
return 1; \
}
SET_VALUE(IggyValueSetF64RS, F64, Value::number(value))
SET_VALUE(IggyValueSetF32RS, F32, Value::number(value))
SET_VALUE(IggyValueSetS32RS, S32, Value::number(value))
SET_VALUE(IggyValueSetU32RS, U32, Value::number(value))
SET_VALUE(IggyValueSetBooleanRS, rrbool, Value::boolean(value != 0))
RADEXPFUNC rrbool RADEXPLINK IggyValueSetStringUTF8RS(IggyValuePath *var, IggyName sub_name, char const *sub_utf8, char const *str, S32 len) {
PropAddr a = addrOf(var, sub_name, sub_utf8, true);
if (!a.ok || !str) return 0;
std::string s(str, str + (len >= 0 ? len : (S32)strlen(str)));
a.obj->setProp(a.prop, Value::string(NameTable::fromUtf8(s)));
return 1;
}
RADEXPFUNC rrbool RADEXPLINK IggyValueSetStringUTF16RS(IggyValuePath *var, IggyName sub_name, char const *sub_utf8, IggyUTF16 const *str, S32 len) {
PropAddr a = addrOf(var, sub_name, sub_utf8, true);
if (!a.ok || !str) return 0;
std::u16string s;
for (S32 i = 0; (len < 0 || i < len) && str[i]; i++) s.push_back((char16_t)str[i]);
a.obj->setProp(a.prop, Value::string(std::move(s)));
return 1;
}
RADEXPFUNC rrbool RADEXPLINK IggyValueSetValueRefRS(IggyValuePath *var, IggyName sub_name, char const *sub_utf8, IggyValueRef value_ref) {
PropAddr a = addrOf(var, sub_name, sub_utf8, true);
if (!a.ok) return 0;
a.obj->setProp(a.prop, value_ref ? Value::object(((IggyObjectNode *)value_ref)->shared_from_this()) : Value::undefined());
return 1;
}
RADEXPFUNC rrbool RADEXPLINK IggyValueSetUserDataRS(IggyValuePath *result, void const *userdata) {
ObjectPtr o = resolveChain(result, true);
if (!o) return 0;
o->userdata = const_cast<void *>(userdata);
return 1;
}
RADEXPFUNC IggyResult RADEXPLINK IggyValueGetUserDataRS(IggyValuePath *result, void **userdata) {
ObjectPtr o = resolveChain(result, false);
if (!o || !userdata) return IGGY_RESULT_Error_ValuePath;
*userdata = o->userdata;
return IGGY_RESULT_SUCCESS;
}
////////////////////////////////////////////////////////////
// Function / method calls -> scene controllers
////////////////////////////////////////////////////////////
RADEXPFUNC IggyResult RADEXPLINK IggyPlayerCallFunctionRS(Iggy *player, IggyDataValue *result, IggyName function, S32 numargs, IggyDataValue *args) {
return (IggyResult)sceneCallMethod(player, player ? player->root : nullptr, function, numargs, args, result);
}
RADEXPFUNC IggyResult RADEXPLINK IggyPlayerCallMethodRS(Iggy *f, IggyDataValue *result, IggyValuePath *target, IggyName methodname, S32 numargs, IggyDataValue *args) {
ObjectPtr obj = resolveChain(target, true);
return (IggyResult)sceneCallMethod(f, obj, methodname, numargs, args, result);
}
////////////////////////////////////////////////////////////
// Events & focus
////////////////////////////////////////////////////////////
RADEXPFUNC void RADEXPLINK IggyMakeEventNone(IggyEvent *e) { if (e) memset(e, 0, sizeof(*e)); }
RADEXPFUNC void RADEXPLINK IggyMakeEventResize(IggyEvent *e) { if (e) { memset(e, 0, sizeof(*e)); e->type = IGGY_EVENTTYPE_Resize; } }
RADEXPFUNC void RADEXPLINK IggyMakeEventActivate(IggyEvent *e, IggyActivestate s) { if (e) { memset(e, 0, sizeof(*e)); e->type = s; } }
RADEXPFUNC void RADEXPLINK IggyMakeEventMouseLeave(IggyEvent *e) { if (e) { memset(e, 0, sizeof(*e)); e->type = IGGY_EVENTTYPE_MouseLeave; } }
RADEXPFUNC void RADEXPLINK IggyMakeEventMouseMove(IggyEvent *e, S32 x, S32 y) { if (e) { memset(e, 0, sizeof(*e)); e->type = IGGY_EVENTTYPE_MouseMove; e->x = x; e->y = y; } }
RADEXPFUNC void RADEXPLINK IggyMakeEventMouseButton(IggyEvent *e, IggyMousebutton b) { if (e) { memset(e, 0, sizeof(*e)); e->type = b; } }
RADEXPFUNC void RADEXPLINK IggyMakeEventMouseWheel(IggyEvent *e, S16 delta) { if (e) { memset(e, 0, sizeof(*e)); e->type = IGGY_EVENTTYPE_MouseWheel; e->keycode = delta; } }
RADEXPFUNC void RADEXPLINK IggyMakeEventKey(IggyEvent *e, IggyKeyevent t, IggyKeycode k, IggyKeyloc loc) { if (e) { memset(e, 0, sizeof(*e)); e->type = t; e->keycode = k; e->keyloc = loc; } }
RADEXPFUNC void RADEXPLINK IggyMakeEventChar(IggyEvent *e, S32 c) { if (e) { memset(e, 0, sizeof(*e)); e->type = IGGY_EVENTTYPE_Char; e->keycode = c; } }
RADEXPFUNC void RADEXPLINK IggyMakeEventFocusLost(IggyEvent *e) { if (e) { memset(e, 0, sizeof(*e)); e->type = IGGY_EVENTTYPE_FocusLost; } }
RADEXPFUNC void RADEXPLINK IggyMakeEventFocusGained(IggyEvent *e, S32 dir) { if (e) { memset(e, 0, sizeof(*e)); e->type = IGGY_EVENTTYPE_Activate; e->keycode = dir; } }
RADEXPFUNC rrbool RADEXPLINK IggyPlayerDispatchEventRS(Iggy *player, IggyEvent *event, IggyEventResult *result) {
if (result) { result->new_flags = event ? event->flags : 0; result->focus_change = IGGY_FOCUS_CHANGE_None; result->focus_direction = 0; }
return sceneDispatchEvent(player, event, result);
}
RADEXPFUNC void RADEXPLINK IggyPlayerSetShiftState(Iggy *, rrbool, rrbool, rrbool, rrbool) {}
RADEXPFUNC void RADEXPLINK IggySetDoubleClickTime(S32) {}
RADEXPFUNC void RADEXPLINK IggySetTextCursorFlash(U32, U32) {}
RADEXPFUNC rrbool RADEXPLINK IggyPlayerHasFocusedEditableTextfield(Iggy *f) { return sceneHasEditableFocus(f); }
RADEXPFUNC rrbool RADEXPLINK IggyPlayerPasteUTF16(Iggy *, U16 *, S32) { return 0; }
RADEXPFUNC rrbool RADEXPLINK IggyPlayerPasteUTF8(Iggy *, char *, S32) { return 0; }
RADEXPFUNC rrbool RADEXPLINK IggyPlayerCut(Iggy *) { return 0; }
RADEXPFUNC S32 RADEXPLINK IggyPlayerCopyUTF16(Iggy *, U16 *, S32) { return IGGY_PLAYER_COPY_no_focused_textfield; }
RADEXPFUNC S32 RADEXPLINK IggyPlayerCopyUTF8(Iggy *, char *, S32) { return IGGY_PLAYER_COPY_no_focused_textfield; }
RADEXPFUNC rrbool RADEXPLINK IggyPlayerGetFocusableObjects(Iggy *f, IggyFocusHandle *current_focus, IggyFocusableObject *objs, S32 max_obj, S32 *num_obj) {
return sceneGetFocusableObjects(f, current_focus, objs, max_obj, num_obj);
}
RADEXPFUNC void RADEXPLINK IggyPlayerSetFocusRS(Iggy *f, IggyFocusHandle object, int focus_key_char) {
sceneSetFocus(f, object, focus_key_char);
}

View File

@@ -0,0 +1,89 @@
// iggy-shim: open reimplementation of the Iggy flash-player C API.
// Internal object model: a Flash-like display/property tree that value paths
// address and scene controllers mutate.
#pragma once
#include <cstdint>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
struct Iggy; // public opaque player type (defined as IggyPlayerImpl below)
namespace shim {
// ---------- interned names (IggyName is a UINTa = pointer to interned utf16) ----------
class NameTable {
public:
// Returns a stable pointer usable as IggyName. Case-sensitive.
uintptr_t intern(const std::u16string &s);
const std::u16string *lookup(uintptr_t name) const;
static std::u16string fromUtf8(const std::string &s);
static std::string toUtf8(const std::u16string &s);
private:
mutable std::mutex mMutex;
std::unordered_set<std::u16string> mStrings;
};
NameTable &names();
// ---------- values ----------
struct IggyObjectNode;
using ObjectPtr = std::shared_ptr<IggyObjectNode>;
struct Value {
enum class Type { Undefined, Null, Boolean, Number, String, Object };
Type type = Type::Undefined;
bool b = false;
double num = 0.0;
std::u16string str;
ObjectPtr obj;
static Value undefined() { return {}; }
static Value boolean(bool v) { Value r; r.type = Type::Boolean; r.b = v; return r; }
static Value number(double v) { Value r; r.type = Type::Number; r.num = v; return r; }
static Value string(std::u16string v) { Value r; r.type = Type::String; r.str = std::move(v); return r; }
static Value object(ObjectPtr v) { Value r; r.type = Type::Object; r.obj = std::move(v); return r; }
double asNumber() const;
bool asBool() const;
std::u16string asString() const;
};
// ---------- display/property object ----------
// One node serves as both a generic AS3 object and a display object.
// Display-specific properties (x, y, visible, alpha, currentFrame, ...) are
// stored as ordinary properties so paths behave uniformly; helpers interpret
// the well-known ones at render time.
struct IggyObjectNode : std::enable_shared_from_this<IggyObjectNode> {
std::u16string name; // instance name in parent
std::u16string className; // symbol/export name that spawned it
std::weak_ptr<IggyObjectNode> parent;
std::vector<ObjectPtr> children; // display order = z order
std::map<std::u16string, Value> props;
std::vector<Value> array; // AS3 Array storage (when used as array)
bool isArray = false;
void *userdata = nullptr;
// Well-known display defaults; overridden by props when present.
// (kept as fields for hot render path: x/y/scale/alpha/visible/frame)
double x = 0, y = 0, scaleX = 1, scaleY = 1, rotation = 0, alpha = 1;
bool visible = true;
int currentFrame = 1;
int totalFrames = 1;
// Sprite art binding: which extracted PNG asset renders this node.
std::string spriteKey; // "<swf>/<charId or export name>"
ObjectPtr childByName(const std::u16string &n);
ObjectPtr ensureChild(const std::u16string &n); // auto-vivify (AS3-ish)
Value getProp(const std::u16string &n);
void setProp(const std::u16string &n, Value v);
void syncFieldFromProp(const std::u16string &n, const Value &v);
};
} // namespace shim

View File

@@ -0,0 +1,79 @@
#pragma once
#include "iggy_object.hpp"
#include <atomic>
#include <chrono>
#include <functional>
// Public opaque types from iggy.h that we define.
struct GDrawFunctions;
struct GDrawTexture;
struct IggyExternalFunctionCallUTF16;
struct IggyCustomDrawCallbackRegion;
namespace shim {
struct SceneController; // per-scene native "document class" (M-C)
struct PlayerImpl; // the real player
// Global (process-wide) state mirroring Iggy's global configuration calls.
struct Globals {
std::mutex mutex;
GDrawFunctions *gdraw = nullptr;
// callbacks registered by the game
void *externalFnUser16 = nullptr;
bool (*externalFn16)(void *, Iggy *, ::IggyExternalFunctionCallUTF16 *) = nullptr;
void *warningUser = nullptr;
void (*warningFn)(void *, Iggy *, int, const char *) = nullptr;
void *customDrawUser = nullptr;
void (*customDrawFn)(void *, Iggy *, ::IggyCustomDrawCallbackRegion *) = nullptr;
void *texSubUser = nullptr;
GDrawTexture *(*texSubCreate)(void *, char16_t *, int32_t *, int32_t *, void **) = nullptr;
void (*texSubDestroy)(void *, void *, GDrawTexture *) = nullptr;
// font registry: family name -> ttf bytes (not owned; game keeps alive)
struct Font { const void *data; int32_t ttcIndex; uint32_t flags; };
std::map<std::u16string, Font> fonts;
std::map<std::u16string, std::u16string> fontIndirects;
std::vector<PlayerImpl *> players; // live players, draw order = creation order
int nextLibraryHandle = 1;
std::map<int, std::string> libraries; // handle -> library url/name
};
Globals &globals();
} // namespace shim
// ---- the public player object (must be layout-opaque; game only holds Iggy*) ----
struct Iggy {
// enough state for the whole shim; lives in the shim heap
shim::ObjectPtr root; // document root ("this" of the movie)
std::string sceneName; // e.g. "StartMenu1080" (from creation url)
std::unique_ptr<shim::SceneController> controller;
// properties exposed via IggyPlayerProperties
int32_t movieW = 1280, movieH = 720;
float fileFps = 30.f, curFps = 30.f;
int32_t framesPassed = 0;
double timePassed = 0, lastTickSeconds = 0, secondsPerDrawnFrame = 1.0 / 60.0;
int32_t displayW = 1280, displayH = 720;
void *userdata = nullptr;
bool valid = true;
bool paused = false;
std::chrono::steady_clock::time_point lastTick{};
// fast names interned per player (we use the global table)
// value-path scratch: paths returned by RootPath/CallbackResultPath
struct IggyValuePath *rootPath = nullptr;
struct IggyValuePath *cbResultPath = nullptr;
shim::Value callbackResult; // written via CallbackResultPath
~Iggy();
};

View File

@@ -0,0 +1,347 @@
// Scene registry implementation (M-A level: identify scenes, build object
// roots, log activity; rendering arrives with the RmlUi/GDraw layer).
#include "scene_registry.hpp"
#include "iggy_player.hpp"
#include "iggy.h"
#include <cstdio>
#include <cstring>
#include <fstream>
#include <sstream>
namespace shim {
// ---------------- crc32 (standard polynomial, table-based) ----------------
static uint32_t crc32buf(const uint8_t *data, size_t len) {
static uint32_t table[256];
static bool init = false;
if (!init) {
for (uint32_t i = 0; i < 256; i++) {
uint32_t c = i;
for (int k = 0; k < 8; k++) c = (c & 1) ? 0xEDB88320u ^ (c >> 1) : c >> 1;
table[i] = c;
}
init = true;
}
uint32_t crc = 0xFFFFFFFFu;
for (size_t i = 0; i < len; i++) crc = table[(crc ^ data[i]) & 0xFF] ^ (crc >> 8);
return crc ^ 0xFFFFFFFFu;
}
// ---------------- fingerprint table ----------------
struct Registry {
std::vector<SceneInfo> scenes;
bool loaded = false;
void load() {
if (loaded) return;
loaded = true;
std::ifstream f("uiassets/scenes.tsv");
if (!f) {
debugLog("scene_registry: uiassets/scenes.tsv not found (cwd must be game dir)");
return;
}
std::string line;
while (std::getline(f, line)) {
if (line.empty() || line[0] == '#') continue;
std::istringstream ss(line);
SceneInfo si;
std::string size, crc, w, h, fps;
if (!std::getline(ss, si.name, '\t')) continue;
std::getline(ss, size, '\t');
std::getline(ss, crc, '\t');
std::getline(ss, w, '\t');
std::getline(ss, h, '\t');
std::getline(ss, fps, '\t');
std::getline(ss, si.docClass, '\t');
si.swfSize = (uint32_t)strtoul(size.c_str(), nullptr, 10);
si.swfCrc = (uint32_t)strtoul(crc.c_str(), nullptr, 16);
si.width = atoi(w.c_str());
si.height = atoi(h.c_str());
si.fps = (float)atof(fps.c_str());
scenes.push_back(std::move(si));
}
debugLog("scene_registry: %d scenes registered", (int)scenes.size());
}
const SceneInfo *identify(const void *data, uint32_t size) {
load();
uint32_t crc = data ? crc32buf((const uint8_t *)data, size < 4096 ? size : 4096) : 0;
for (const auto &s : scenes)
if (s.swfSize == size && s.swfCrc == crc) return &s;
return nullptr;
}
const SceneInfo *byName(const std::string &name) {
load();
for (const auto &s : scenes)
if (s.name == name) return &s;
return nullptr;
}
};
static Registry &registry() {
static Registry r;
return r;
}
// ---------------- NameTable ----------------
uintptr_t NameTable::intern(const std::u16string &s) {
std::lock_guard<std::mutex> lock(mMutex);
auto it = mStrings.insert(s).first;
return (uintptr_t)&*it;
}
const std::u16string *NameTable::lookup(uintptr_t name) const {
return name ? (const std::u16string *)name : nullptr;
}
std::u16string NameTable::fromUtf8(const std::string &s) {
std::u16string out;
size_t i = 0;
while (i < s.size()) {
uint32_t cp = (uint8_t)s[i];
int extra = 0;
if (cp >= 0xF0) { cp &= 0x07; extra = 3; }
else if (cp >= 0xE0) { cp &= 0x0F; extra = 2; }
else if (cp >= 0xC0) { cp &= 0x1F; extra = 1; }
i++;
while (extra-- > 0 && i < s.size()) cp = (cp << 6) | ((uint8_t)s[i++] & 0x3F);
if (cp >= 0x10000) {
cp -= 0x10000;
out.push_back((char16_t)(0xD800 + (cp >> 10)));
out.push_back((char16_t)(0xDC00 + (cp & 0x3FF)));
} else {
out.push_back((char16_t)cp);
}
}
return out;
}
std::string NameTable::toUtf8(const std::u16string &s) {
std::string out;
size_t i = 0;
while (i < s.size()) {
uint32_t cp = s[i++];
if (cp >= 0xD800 && cp < 0xDC00 && i < s.size()) {
uint32_t lo = s[i];
if (lo >= 0xDC00 && lo < 0xE000) { cp = 0x10000 + ((cp - 0xD800) << 10) + (lo - 0xDC00); i++; }
}
if (cp < 0x80) out.push_back((char)cp);
else if (cp < 0x800) { out.push_back((char)(0xC0 | (cp >> 6))); out.push_back((char)(0x80 | (cp & 0x3F))); }
else if (cp < 0x10000) {
out.push_back((char)(0xE0 | (cp >> 12)));
out.push_back((char)(0x80 | ((cp >> 6) & 0x3F)));
out.push_back((char)(0x80 | (cp & 0x3F)));
} else {
out.push_back((char)(0xF0 | (cp >> 18)));
out.push_back((char)(0x80 | ((cp >> 12) & 0x3F)));
out.push_back((char)(0x80 | ((cp >> 6) & 0x3F)));
out.push_back((char)(0x80 | (cp & 0x3F)));
}
}
return out;
}
// ---------------- Value & object model ----------------
double Value::asNumber() const {
switch (type) {
case Type::Number: return num;
case Type::Boolean: return b ? 1.0 : 0.0;
case Type::String: return atof(NameTable::toUtf8(str).c_str());
default: return 0.0;
}
}
bool Value::asBool() const {
switch (type) {
case Type::Boolean: return b;
case Type::Number: return num != 0.0;
case Type::String: return !str.empty();
case Type::Object: return obj != nullptr;
default: return false;
}
}
std::u16string Value::asString() const {
switch (type) {
case Type::String: return str;
case Type::Number: {
char buf[32];
if (num == (int64_t)num) snprintf(buf, sizeof(buf), "%lld", (long long)num);
else snprintf(buf, sizeof(buf), "%g", num);
return NameTable::fromUtf8(buf);
}
case Type::Boolean: return b ? u"true" : u"false";
default: return u"";
}
}
ObjectPtr IggyObjectNode::childByName(const std::u16string &n) {
for (auto &c : children)
if (c && c->name == n) return c;
auto it = props.find(n);
if (it != props.end() && it->second.type == Value::Type::Object) return it->second.obj;
return nullptr;
}
ObjectPtr IggyObjectNode::ensureChild(const std::u16string &n) {
if (ObjectPtr c = childByName(n)) return c;
auto c = std::make_shared<IggyObjectNode>();
c->name = n;
c->parent = weak_from_this();
children.push_back(c);
return c;
}
Value IggyObjectNode::getProp(const std::u16string &n) {
// well-known display fields first
if (n == u"x") return Value::number(x);
if (n == u"y") return Value::number(y);
if (n == u"alpha") return Value::number(alpha);
if (n == u"visible") return Value::boolean(visible);
if (n == u"scaleX") return Value::number(scaleX);
if (n == u"scaleY") return Value::number(scaleY);
if (n == u"rotation") return Value::number(rotation);
if (n == u"currentFrame") return Value::number(currentFrame);
if (n == u"totalFrames") return Value::number(totalFrames);
auto it = props.find(n);
if (it != props.end()) return it->second;
if (ObjectPtr c = childByName(n)) return Value::object(c);
return Value::undefined();
}
void IggyObjectNode::setProp(const std::u16string &n, Value v) {
syncFieldFromProp(n, v);
props[n] = std::move(v);
}
void IggyObjectNode::syncFieldFromProp(const std::u16string &n, const Value &v) {
if (n == u"x") x = v.asNumber();
else if (n == u"y") y = v.asNumber();
else if (n == u"alpha") alpha = v.asNumber();
else if (n == u"visible") visible = v.asBool();
else if (n == u"scaleX") scaleX = v.asNumber();
else if (n == u"scaleY") scaleY = v.asNumber();
else if (n == u"rotation") rotation = v.asNumber();
else if (n == u"currentFrame") currentFrame = (int)v.asNumber();
}
// ---------------- players ----------------
struct SceneController {
virtual ~SceneController() = default;
};
} // namespace shim
// requires complete SceneController (unique_ptr member)
Iggy::~Iggy() = default;
namespace shim {
Iggy *sceneCreatePlayerFromData(const void *data, uint32_t size, const char *nameHint) {
const SceneInfo *info = registry().identify(data, size);
auto *p = new Iggy();
p->root = std::make_shared<IggyObjectNode>();
p->root->name = u"root";
if (info) {
p->sceneName = info->name;
p->movieW = info->width;
p->movieH = info->height;
p->fileFps = p->curFps = info->fps;
p->root->className = NameTable::fromUtf8(info->docClass);
debugLog("player create: scene=%s (%dx%d @%.0f) doc=%s", info->name.c_str(),
info->width, info->height, info->fps, info->docClass.c_str());
} else {
p->sceneName = nameHint ? nameHint : "";
debugLog("player create: UNIDENTIFIED swf size=%u hint=%s", size, nameHint ? nameHint : "");
}
{
auto &g = globals();
std::lock_guard<std::mutex> lock(g.mutex);
g.players.push_back((PlayerImpl *)p);
}
return p;
}
Iggy *sceneCreatePlayer(const std::string &name) {
const SceneInfo *info = registry().byName(name);
(void)info;
return sceneCreatePlayerFromData(nullptr, 0, name.c_str());
}
void sceneDestroyPlayer(Iggy *player) {
debugLog("player destroy: %s", player->sceneName.c_str());
delete player->rootPath;
delete player->cbResultPath;
delete player;
}
void scenePlayerTick(Iggy *player, bool isInit) {
if (!player) return;
auto now = std::chrono::steady_clock::now();
if (player->framesPassed > 0) {
player->lastTickSeconds = std::chrono::duration<double>(now - player->lastTick).count();
player->timePassed += player->lastTickSeconds;
}
player->lastTick = now;
player->framesPassed++;
if (isInit) debugLog("init tick: %s", player->sceneName.c_str());
}
void scenePlayerDraw(Iggy *player) {
// M-A: nothing rendered yet. M-B renders the scene's display tree
// through the GDrawFunctions vtable the game installed.
(void)player;
}
int32_t sceneCallMethod(Iggy *player, const ObjectPtr &target, uintptr_t methodName,
int32_t numArgs, IggyDataValue *args, IggyDataValue *result) {
if (result) {
memset(result, 0, sizeof(*result));
result->type = IGGY_DATATYPE_undefined;
}
if (!player) return IGGY_RESULT_Error_InvalidIggy;
const std::u16string *m = names().lookup(methodName);
static int logBudget = 500;
if (m && logBudget > 0) {
logBudget--;
debugLog("call %s.%s(%d args)", player->sceneName.c_str(), NameTable::toUtf8(*m).c_str(), numArgs);
}
(void)target;
(void)args;
return IGGY_RESULT_SUCCESS;
}
int32_t sceneDispatchEvent(Iggy *player, IggyEvent *event, IggyEventResult *result) {
(void)player;
(void)event;
(void)result;
return 0;
}
int32_t sceneGetFocusableObjects(Iggy *player, void **currentFocus, void *objs,
int32_t maxObj, int32_t *numObj) {
(void)player;
(void)objs;
(void)maxObj;
if (currentFocus) *currentFocus = nullptr;
if (numObj) *numObj = 0;
return 1;
}
void sceneSetFocus(Iggy *player, void *object, int) {
(void)player;
(void)object;
}
int32_t sceneHasEditableFocus(Iggy *) { return 0; }
void sceneOnGDrawSet(GDrawFunctions *gdraw) {
debugLog("gdraw installed: %p", (void *)gdraw);
}
void sceneOnFontInstalled(const std::u16string &, const void *, int32_t, uint32_t) {}
} // namespace shim

View File

@@ -0,0 +1,54 @@
// Scene registry: identifies which converted scene a player runs (by
// fingerprinting the SWF bytes the game still hands us), owns scene assets,
// and hosts the tick/draw/method-call/event entry points the API layer calls.
#pragma once
#include "iggy_object.hpp"
#include <cstdint>
struct Iggy;
struct GDrawFunctions;
struct IggyEvent;
struct IggyEventResult;
struct IggyDataValue;
namespace shim {
// scenes.tsv row (generated by extract-ui-pngs.sh from the layout manifests)
struct SceneInfo {
std::string name; // e.g. "StartMenu1080"
uint32_t swfSize = 0; // exact byte size of the original SWF
uint32_t swfCrc = 0; // crc32 of the first 4096 bytes
int width = 1280, height = 720;
float fps = 30.f;
std::string docClass; // e.g. "fourj.documents.StartMenu"
};
// creation & lifecycle (called from the C API layer)
Iggy *sceneCreatePlayerFromData(const void *data, uint32_t size, const char *nameHint);
Iggy *sceneCreatePlayer(const std::string &name);
void sceneDestroyPlayer(Iggy *player);
// per-frame
void scenePlayerTick(Iggy *player, bool isInit);
void scenePlayerDraw(Iggy *player);
// game -> scene method dispatch (SetHealth etc.)
int32_t sceneCallMethod(Iggy *player, const ObjectPtr &target, uintptr_t methodName,
int32_t numArgs, IggyDataValue *args, IggyDataValue *result);
// input / focus
int32_t sceneDispatchEvent(Iggy *player, IggyEvent *event, IggyEventResult *result);
int32_t sceneGetFocusableObjects(Iggy *player, void **currentFocus, void *objs,
int32_t maxObj, int32_t *numObj);
void sceneSetFocus(Iggy *player, void *object, int focusKeyChar);
int32_t sceneHasEditableFocus(Iggy *player);
// global hooks
void sceneOnGDrawSet(GDrawFunctions *gdraw);
void sceneOnFontInstalled(const std::u16string &name, const void *ttf, int32_t ttcIndex, uint32_t flags);
void debugLog(const char *fmt, ...);
} // namespace shim

View File

@@ -0,0 +1,15 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fb25a2a7..a37d3c5a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -93,7 +93,9 @@ set(MINECRAFT_SHARED_DEFINES
# Add platform-specific defines
if(PLATFORM_NAME STREQUAL "Windows64")
list(APPEND MINECRAFT_SHARED_DEFINES _WINDOWS64)
- set(IGGY_LIBS iggy_w64.lib)
+ if(NOT IGGY_LIBS)
+ set(IGGY_LIBS iggy_w64.lib)
+ endif()
endif()
list(APPEND MINECRAFT_SHARED_DEFINES ${PLATFORM_DEFINES})