aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit e3f7dd6818b357b7dfe9af3aad0295c48b1fc73e
parent e1c1c51d31891f2ef31335d8d270ca16e8ebf930
Author: anon <anon@example.com>
Date:   Sun, 25 Oct 2026 07:24:09 +0000

Support durable map uploads and native map rendering

Apply all 55 original map and reader contracts through shared requirements. Persist learned banks atomically with item consumption and restore them through the native protocol. Support the depth, blending and vertex layouts reached by local maps and their markers.

Verified with the full Go suite, focused race tests, vet, RTX OpenGL and Chromium WebGL device regressions, context restoration, and actual HTTPS WASM uploads, rejection cases and cold recovery. Document the older Hit mask reconstruction policy and remaining shop-stock work.

Diffstat:
MTODO.md | 5++++-
Mclient/runtime/gl_renderer.c | 13++++++++-----
Mclient/runtime/gl_renderer.h | 2+-
Mclient/runtime/linux_graphics.c | 28+++++++++++++++-------------
Mclient/tests/browser_context.c | 2+-
Mclient/tests/devices.c | 133+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adocs/map-uploads.md | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/backpacks.go | 3+++
Mserver/inventory.go | 2++
Mserver/item_database.go | 8+++++---
Mserver/item_requirements.go | 7+++++++
Mserver/item_store.go | 5+++--
Aserver/map_upload.go | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/map_upload_test.go | 297+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/target_protocol_test.go | 2+-
Mserver/weapon_stats.go | 2++
Mserver/world.go | 3+++
Mserver/world.sql | 5++++-
18 files changed, 690 insertions(+), 28 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -530,7 +530,7 @@ introduction and starting-item gameplay remain open below. shared catalog rules, including Meta Shield AC and solar Fling. Omni shirt and basic boards now wear through shared catalog clothing rules; owner/observer appearance/AC, faction rejection and cold recovery are verified. - Startup crystals, First Aid use, maps, shell, board upgrades and remaining + Startup crystals, First Aid use, shell, board upgrades and remaining weapon specials (Burst, Aimed Shot, Brawl and Dimach) still need gameplay support. Verify those actions and each starting profession in its real training ground. Corroborate the four provisional pistol allocations, MA Oak Bo allocation, @@ -613,6 +613,9 @@ introduction and starting-item gameplay remain open below. native live object delivery and any packing rules before admitting these categories. Cover full inventory, freed sale slots, partial failure and stable ownership across reconnect/restart without inventing extra packet identity fields. +- [ ] Recover map-terminal stock membership and sell the supported area maps + and reader upgrades. Verify exact item/price delivery, purchase-to-upload, + faction and skill rejection, duplicate purchases and durable consumption. - [ ] Recover medical and ammunition stock membership and QL generation beyond the current basic QL1 recovery subset. Original medical descriptions establish broad families, while tier descriptors differ; do not copy basic stock into diff --git a/client/runtime/gl_renderer.c b/client/runtime/gl_renderer.c @@ -38,7 +38,7 @@ static GLint texture_color_arg1[2], texture_alpha_arg1[2]; static GLint texture_factor; static GLint fog_enabled, fog_color; static GLint alpha_function, alpha_reference; -static int depth_write = 1; +static int depth_enabled = 1, depth_write = 1; static uint32_t depth_function = 4; static uint32_t depth_bias; static uint32_t cull_mode = 1; @@ -605,8 +605,9 @@ static void draw_data(struct gl_target *target, unsigned primitive, glCullFace(cull_mode == 2 ? GL_FRONT : GL_BACK); } } - if (!applied.raster_valid || applied.depth_test != (target->depth != NULL)) { - if (target->depth) glEnable(GL_DEPTH_TEST); + int depth_test = depth_enabled && target->depth; + if (!applied.raster_valid || applied.depth_test != depth_test) { + if (depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); } if (!applied.raster_valid || applied.depth_function != depth_function) @@ -622,7 +623,7 @@ static void draw_data(struct gl_target *target, unsigned primitive, } applied.raster_valid = 1; applied.cull = cull_mode; - applied.depth_test = target->depth != NULL; + applied.depth_test = depth_test; applied.depth_function = depth_function; applied.depth_write = depth_write; applied.depth_bias = depth_bias; @@ -898,8 +899,9 @@ void gl_renderer_set_texture(unsigned stage, const struct gl_texture_state *stat glActiveTexture(GL_TEXTURE0); } -void gl_renderer_set_depth(int write, uint32_t function, uint32_t bias) +void gl_renderer_set_depth(int enabled, int write, uint32_t function, uint32_t bias) { + depth_enabled = enabled; depth_write = write; depth_function = function; depth_bias = bias; @@ -919,6 +921,7 @@ static GLenum blend_factor(uint32_t factor) case 3: return GL_SRC_COLOR; case 5: return GL_SRC_ALPHA; case 6: return GL_ONE_MINUS_SRC_ALPHA; + case 9: return GL_DST_COLOR; default: abort(); } } diff --git a/client/runtime/gl_renderer.h b/client/runtime/gl_renderer.h @@ -68,7 +68,7 @@ void gl_renderer_set_texture(unsigned stage, const struct gl_texture_state *stat void gl_renderer_set_fog(int enabled, uint32_t color); void gl_renderer_set_alpha_test(int enabled, uint32_t function, uint32_t reference); void gl_renderer_set_blend(int enabled, uint32_t source, uint32_t destination); -void gl_renderer_set_depth(int write, uint32_t function, uint32_t bias); +void gl_renderer_set_depth(int enabled, int write, uint32_t function, uint32_t bias); void gl_renderer_set_cull(uint32_t mode); #endif diff --git a/client/runtime/linux_graphics.c b/client/runtime/linux_graphics.c @@ -100,7 +100,7 @@ static struct device_object { uint32_t interface, references, cull; struct texture_stage stages[2]; uint32_t fog_enabled, fog_color, fog_start, fog_end, fog_density, fog_vertex_mode; - uint32_t blend, source_blend, destination_blend, depth_write, depth_function, clipping, lighting; + uint32_t blend, source_blend, destination_blend, depth_enabled, depth_write, depth_function, clipping, lighting; uint32_t depth_bias; uint32_t texture_factor; uint32_t specular; @@ -566,7 +566,7 @@ static void describe_device(uint32_t record) MEM32(record + 64) = 0x10; /* Triangle culling: NONE */ MEM32(record + 68) = 0x10; /* Triangle rasterization: ZTEST */ MEM32(record + 72) = 8; /* Depth comparison: LESSEQUAL */ - MEM32(record + 76) = MEM32(record + 80) = 0x37; /* ZERO, ONE, SRCCOLOR, SRCALPHA, INVSRCALPHA. */ + MEM32(record + 76) = MEM32(record + 80) = 0x137; /* ZERO, ONE, SRCCOLOR, SRCALPHA, INVSRCALPHA, DESTCOLOR. */ MEM32(record + 84) = 0xff; /* All eight alpha comparison functions. */ MEM32(record + 88) = 8; /* Gouraud RGB interpolation */ MEM32(record + 92) = 0x45; /* Perspective, alpha, normalized repeat range. */ @@ -1563,6 +1563,7 @@ static void create_device(void) device->source_blend = 2; device->alpha_function = 8; device->destination_blend = 1; + device->depth_enabled = 1; device->depth_write = 1; device->depth_function = 4; device->clipping = 1; @@ -1813,7 +1814,7 @@ static uint32_t device_state(struct device_object *device, uint32_t state) case 147: case 151: case 152: return 0; case 148: return device->emissive_source; case 146: return device->specular_source; - case 7: return 1; /* Z enable. */ + case 7: return device->depth_enabled; case 137: return device->lighting; case 14: return device->depth_write; case 8: return 3; /* Solid fill. */ @@ -1891,7 +1892,8 @@ static void device_set_state(void) { struct device_object *device = find_device(MEM32(g_esp + 4)); uint32_t state = MEM32(g_esp + 8), value = MEM32(g_esp + 12); - if (state == 22 && value >= 1 && value <= 3) device->cull = value; + if (state == 7 && value <= 1) device->depth_enabled = value; + else if (state == 22 && value >= 1 && value <= 3) device->cull = value; else if (state == 27 && value <= 1) device->blend = value; else if (state == 28 && value <= 1) device->fog_enabled = value; else if (state == 29 && value <= 1) device->specular = value; @@ -1915,8 +1917,8 @@ static void device_set_state(void) /* Supported untransformed formats omit color 2, which falls back to the material. */ else if (state == 146 && (value == 0 || value == 2)) device->specular_source = value; else if (state == 148 && value <= 2) device->emissive_source = value; - else if (state == 19 && (value == 1 || value == 2 || value == 3 || value == 5 || value == 6)) device->source_blend = value; - else if (state == 20 && (value == 1 || value == 2 || value == 3 || value == 5 || value == 6)) device->destination_blend = value; + else if (state == 19 && (value == 1 || value == 2 || value == 3 || value == 5 || value == 6 || value == 9)) device->source_blend = value; + else if (state == 20 && (value == 1 || value == 2 || value == 3 || value == 5 || value == 6 || value == 9)) device->destination_blend = value; else if (value != device_state(device, state)) { fprintf(stderr, "Unsupported Direct3D render state %u value=%08x\n", state, value); exit(3); } @@ -1986,7 +1988,7 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin unsigned texture_count = (fvf >> 8) & 15, format = fvf & ~0x300u; int untransformed = texture_count >= 1 && (format == 0x12 || format == 0x52 || format == 0x42); if ((primitive != 2 && primitive != 4 && primitive != 5 && primitive != 6) || texture_count > 2 || - (format != 0x44 && format != 0xc4 && !untransformed) || flags) { + ((format & ~0xc0u) != 4 && !untransformed) || flags) { fprintf(stderr, "Unsupported Direct3D draw primitive=%u fvf=%08x flags=%08x cull=%u\n", primitive, fvf, flags, device->cull); exit(3); } g_eax = 0x80070057u; @@ -2086,8 +2088,8 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin gpu.flags[3] = device->emissive_source == 1 && (fvf & 0x40); } gl_renderer_set_vertex_transform(gpu_transform ? &gpu : NULL); - /* Pretransformed vertices carry diffuse and optional specular colors. */ - uint32_t uv_offset = 20 + (fvf & 0x80 ? 4 : 0), stride = uv_offset + texture_count * 8; + /* Pretransformed vertices place optional colors before their UV sets. */ + uint32_t uv_offset = 16 + (fvf & 0x40 ? 4 : 0) + (fvf & 0x80 ? 4 : 0), stride = uv_offset + texture_count * 8; if (untransformed) stride = 12 + (fvf & 0x10 ? 12 : 0) + (fvf & 0x40 ? 4 : 0) + texture_count * 8; const void *raw_vertices = gpu_transform ? (const void *)ADDR(input) : NULL; if (raw_vertices) { @@ -2186,14 +2188,14 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin vertices[i].position[1] = (1 - 2 * (position[1] + 0.5f) / device->target->height) * w; vertices[i].position[2] = position[2] * w; vertices[i].position[3] = w; - uint32_t color = MEM32(input + i * stride + 16); + uint32_t color = fvf & 0x40 ? MEM32(input + i * stride + 16) : UINT32_MAX; vertices[i].color[0] = ((color >> 16) & 255) / 255.0f; vertices[i].color[1] = ((color >> 8) & 255) / 255.0f; vertices[i].color[2] = (color & 255) / 255.0f; vertices[i].color[3] = (color >> 24) / 255.0f; - vertices[i].fog = fvf & 0x80 ? (MEM32(input + i * stride + 20) >> 24) / 255.0f : 0; + uint32_t specular = fvf & 0x80 ? MEM32(input + i * stride + uv_offset - 4) : 0; + vertices[i].fog = (specular >> 24) / 255.0f; if (device->specular && (fvf & 0x80)) { - uint32_t specular = MEM32(input + i * stride + 20); for (unsigned j = 0; j < 3; ++j) vertices[i].specular[j] = ((specular >> (16 - j * 8)) & 255) / 255.0f; } for (unsigned stage = 0; stage < 2; ++stage) { @@ -2231,7 +2233,7 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin gl_renderer_set_fog(device->fog_enabled, device->fog_color); gl_renderer_set_alpha_test(device->alpha_test, device->alpha_function, device->alpha_reference); gl_renderer_set_blend(device->blend, device->source_blend, device->destination_blend); - gl_renderer_set_depth(device->depth_write, device->depth_function, device->depth_bias); + gl_renderer_set_depth(device->depth_enabled, device->depth_write, device->depth_function, device->depth_bias); gl_renderer_set_cull(device->cull); const int32_t clip[] = {device->viewport[0], device->viewport[1], device->viewport[2], device->viewport[3]}; if (raw_vertices) { diff --git a/client/tests/browser_context.c b/client/tests/browser_context.c @@ -221,7 +221,7 @@ static bool restored_frame(double timestamp, void *argument) gl_renderer_set_alpha_test(0, 8, 0); gl_renderer_set_blend(0, 1, 1); gl_renderer_set_fog(0, 0); - gl_renderer_set_depth(1, 4, 0); + gl_renderer_set_depth(1, 1, 4, 0); gl_target_clear(first, 0xff000000, 1); gl_target_clear(second, 0xff000000, 1); gl_target_draw(first, 4, vertices, 4, indices, 6, clip); diff --git a/client/tests/devices.c b/client/tests/devices.c @@ -1007,6 +1007,136 @@ static void depth_write_controls_occlusion(uint32_t device, uint32_t target) } } +static void disabling_depth_preserves_occlusion(uint32_t device, uint32_t target) +{ + const uint32_t first_pixels[2][2] = {{0xff0000, 0xff0000}, {0x102030, 0xff0000}}; + const uint32_t final_pixels[2][2] = {{0xff0000, 0x00ff00}, {0x102030, 0xff0000}}; + assert(!invoke(device, 21, 3, 7u, workspace()) && *memory(workspace()) == 1); + for (unsigned enabled = 0; enabled <= 1; ++enabled) for (unsigned closer = 0; closer <= 1; ++closer) { + uint32_t input = workspace() + 512, desc = workspace() + 128; + struct vertex { float x, y, z, rhw; uint32_t color; } vertices[] = { + {0, 0, 0, 1, 0xffff0000}, {32, 0, 0, 1, 0xffff0000}, {0, 32, 0, 1, 0xffff0000} + }; + assert(!invoke(device, 20, 3, 7u, enabled)); + assert(!invoke(device, 21, 3, 7u, workspace()) && *memory(workspace()) == enabled); + assert(!invoke(device, 10, 7, 0u, 0u, 3u, 0xff102030u, 0x3f000000u, 0u)); + for (unsigned i = 0; i < 3; ++i) vertices[i].z = closer ? .25f : .75f; + memcpy(memory(input), vertices, sizeof(vertices)); + + assert(!invoke(device, 5, 1)); + assert(!invoke(device, 25, 6, 4u, 0x44u, input, 3u, 0u)); + assert(!invoke(device, 6, 1)); + + *memory(desc) = 124; + assert(!invoke(target, 25, 5, 0u, desc, 0x11u, 0u)); + uint32_t pixels = *memory(desc + 36), pitch = *memory(desc + 16); + assert((*memory(pixels + 6 * pitch + 6 * 4) & 0xffffff) == first_pixels[enabled][closer]); + assert(!invoke(target, 32, 2, 0u)); + + // Restore depth testing against the buffer retained by the first draw. + assert(!invoke(device, 20, 3, 7u, 1u)); + for (unsigned i = 0; i < 3; ++i) { + vertices[i].z = closer ? .375f : .625f; + vertices[i].color = 0xff00ff00; + } + memcpy(memory(input), vertices, sizeof(vertices)); + assert(!invoke(device, 5, 1)); + assert(!invoke(device, 25, 6, 4u, 0x44u, input, 3u, 0u)); + assert(!invoke(device, 6, 1)); + + *memory(desc) = 124; + assert(!invoke(target, 25, 5, 0u, desc, 0x11u, 0u)); + pixels = *memory(desc + 36); pitch = *memory(desc + 16); + assert((*memory(pixels + 6 * pitch + 6 * 4) & 0xffffff) == final_pixels[enabled][closer]); + assert((*memory(pixels + 31 * pitch + 31 * 4) & 0xffffff) == 0x102030); + assert(!invoke(target, 32, 2, 0u)); + } +} + +static void transformed_fans_without_diffuse_use_white(uint32_t draw, uint32_t device, uint32_t target) +{ + uint32_t desc = workspace() + 128, input = workspace() + 512; + memset(memory(desc), 0, 124); + *memory(desc) = 124; *memory(desc + 4) = 0x1007; + *memory(desc + 8) = *memory(desc + 12) = 2; *memory(desc + 104) = 0x1000; + const uint32_t format[] = {32, 0x41, 0, 32, 0xff0000, 0xff00, 0xff, 0xff000000}; + memcpy(memory(desc + 72), format, 32); + assert(!invoke(draw, 6, 4, desc, workspace(), 0u)); + uint32_t texture = *memory(workspace()); + assert(!invoke(texture, 25, 5, 0u, desc, 0x21u, 0u)); + uint32_t pixels = *memory(desc + 36), pitch = *memory(desc + 16); + *memory(pixels) = 0xffff0000; *memory(pixels + 4) = 0xff00ff00; + *memory(pixels + pitch) = 0xff0000ff; *memory(pixels + pitch + 4) = 0xffffffff; + assert(!invoke(texture, 32, 2, 0u)); + assert(!invoke(device, 35, 3, 0u, texture)); + const float positions[][4] = {{4,4,.25f,1}, {28,4,.25f,1}, {28,28,.25f,1}, {4,28,.25f,1}}; + for (unsigned textures = 0; textures <= 2; ++textures) for (unsigned specular = 0; specular <= 1; ++specular) { + unsigned stride = 16 + specular * 4 + textures * 8; + for (unsigned i = 0; i < 4; ++i) { + uint32_t vertex = input + i * stride; + memcpy(memory(vertex), positions[i], 16); + if (specular) *memory(vertex + 16) = 0xff010203; + const float uv[] = {.75f, .25f}; + if (textures == 2) memset(memory(vertex + 16 + specular * 4), 0, 8); + if (textures) memcpy(memory(vertex + stride - 8), uv, 8); + } + assert(!invoke(device, 35, 3, 0u, textures ? texture : 0u)); + assert(!invoke(device, 37, 4, 0u, 11u, textures ? textures - 1 : 0u)); + assert(!invoke(device, 20, 3, 28u, specular)); + assert(!invoke(device, 20, 3, 34u, 0xff102030u)); + assert(!invoke(device, 10, 7, 0u, 0u, 3u, 0xff102030u, 0x3f800000u, 0u)); + + assert(!invoke(device, 5, 1)); + assert(!invoke(device, 25, 6, 6u, 4u | textures << 8 | specular << 7, input, 4u, 0u)); + assert(!invoke(device, 6, 1)); + + *memory(desc) = 124; + assert(!invoke(target, 25, 5, 0u, desc, 0x11u, 0u)); + pixels = *memory(desc + 36); pitch = *memory(desc + 16); + assert((*memory(pixels + 10 * pitch + 10 * 4) & 0xffffff) == (textures ? 0x00ff00 : 0xffffff)); + assert((*memory(pixels + 23 * pitch + 23 * 4) & 0xffffff) == (textures ? 0x00ff00 : 0xffffff)); + assert((*memory(pixels) & 0xffffff) == 0x102030); + assert(!invoke(target, 32, 2, 0u)); + } + assert(!invoke(device, 20, 3, 28u, 0u)); + assert(!invoke(device, 37, 4, 0u, 11u, 0u)); + assert(!invoke(device, 35, 3, 0u, 0u)); + invoke(texture, 2, 1); +} + +static void destination_color_blending_multiplies_channels(uint32_t device, uint32_t target) +{ + const uint32_t multiplied[] = {0x202018, 0x401004}; + assert(!invoke(device, 3, 2, workspace())); + assert((*memory(workspace() + 76) & 0x100) && (*memory(workspace() + 80) & 0x100)); + for (unsigned destination = 0; destination <= 1; ++destination) for (unsigned enabled = 0; enabled <= 1; ++enabled) { + uint32_t input = workspace() + 512, desc = workspace() + 128; + struct vertex { float x, y, z, rhw; uint32_t color; } vertices[] = { + {0, 0, .25f, 1, 0xff4080c0}, {32, 0, .25f, 1, 0xff4080c0}, {0, 32, .25f, 1, 0xff4080c0} + }; + assert(!invoke(device, 20, 3, 27u, enabled)); + assert(!invoke(device, 20, 3, 19u, destination ? 1u : 9u)); + assert(!invoke(device, 20, 3, 20u, destination ? 9u : 1u)); + assert(!invoke(device, 21, 3, destination ? 20u : 19u, workspace()) && *memory(workspace()) == 9); + assert(!invoke(device, 10, 7, 0u, 0u, 3u, 0xff804020u, 0x3f800000u, 0u)); + memcpy(memory(input), vertices, sizeof(vertices)); + + assert(!invoke(device, 5, 1)); + assert(!invoke(device, 25, 6, 4u, 0x44u, input, 3u, 0u)); + assert(!invoke(device, 6, 1)); + + *memory(desc) = 124; + assert(!invoke(target, 25, 5, 0u, desc, 0x11u, 0u)); + uint32_t pixels = *memory(desc + 36), pitch = *memory(desc + 16); + assert((*memory(pixels + 6 * pitch + 6 * 4) & 0xffffff) == (enabled ? multiplied[destination] : 0x4080c0)); + assert((*memory(pixels + 31 * pitch + 31 * 4) & 0xffffff) == 0x804020); + assert(!invoke(target, 32, 2, 0u)); + } + assert(!invoke(device, 20, 3, 27u, 0u)); + assert(!invoke(device, 20, 3, 19u, 2u)); + assert(!invoke(device, 20, 3, 20u, 1u)); +} + static void depth_comparisons_control_visibility(uint32_t device, uint32_t target) { const unsigned visible[8][3] = {{0,0,0}, {1,0,0}, {0,1,0}, {1,1,0}, @@ -1879,6 +2009,7 @@ static void device_lifetime_and_rendering(const char *pixels_path) } assert(!invoke(color, 32, 2, 0u)); assert(fwrite(rgb, 1, sizeof(rgb), file) == sizeof(rgb)); + transformed_fans_without_diffuse_use_white(draw, device, color); textured_triangles(draw, device, color, file); mip_levels_render_after_edits_and_eviction(draw, device, color); transformed_vertex_fog_blends_rgb(device, color, file); @@ -1887,6 +2018,8 @@ static void device_lifetime_and_rendering(const char *pixels_path) vertex_buffer_writes_update_rendered_pixels(draw, device, color); rectangle_clears_preserve_outside_depth(device, color, file); depth_write_controls_occlusion(device, color); + disabling_depth_preserves_occlusion(device, color); + destination_color_blending_multiplies_channels(device, color); depth_comparisons_control_visibility(device, color); transformed_render_states_preserve_rasterization(device, color); viewport_limits_clearing_and_drawing(device, color, file); diff --git a/docs/map-uploads.md b/docs/map-uploads.md @@ -0,0 +1,104 @@ +# Map uploads + +Map knowledge belongs to the player, independently of the consumed map item. +The server stores MapOptions (470), MapAreaPart1 (471) and MapAreaPart2 (472) +alongside the inventory. Uploading a supported map commits the updated banks +and removal of its one owned instance in the same SQLite transaction. A failed +transaction publishes neither change. FullCharacter restores all three banks. + +## Original contracts + +The original resource audit found 55 complete QL1 upload contracts: 47 individual +area maps, three faction starter bundles and five reader upgrades. The server +admits their immediate OnUse contracts and evaluates their authored postfix +requirements using effective Map Navigation, faction and intrinsic map banks. +It does not impose an extra universal duplicate rule. + +| Starter | Faction | MapAreaPart1 | MapAreaPart2 | +| --- | --- | --- | --- | +| 116693 Omni | 2 | 0x00018c00 | 0x1600403b | +| 116696 Clan | 1 | 0x1180000e | 0xc1000000 | +| 116697 Neutral | 0 | 0x00004000 | 0x20001840 | + +Omni's original requirements test bank 471 twice. Clan and Neutral test both +area banks. Full Athen Shire, Newland Desert, Newland City, Newland and Mutan +Domain permit another upload; maps with missing-bit requirements reject it. +Signed high-bit masks are retained as unsigned 32-bit banks. + +Reader upgrades add these MapOptions bits: Side 1, Monsters 2, People 4, +Machines 8 and Arrow 16. Their authored strict skill comparisons require +effective Map Navigation of at least 450, 130, 80, 50 and 25 respectively. + +Eight maps use native SetFlag, which ORs a bit into an existing bank. The other +47 use the older Hit effect. The retained client's Hit handler does not install +these maps locally, and the original server implementation is unavailable. +The server reconstructs that effect by ORing the authored masks, preserving +earlier knowledge even for maps whose criteria permit re-upload. This is an +explicit reconstruction policy, not proof of the original server's arithmetic. + +## Native delivery and rendering + +StatIIR updates exactly one stat/value pair. A successful upload sends the use +acknowledgement, three separate StatIIR packets and the inventory removal. +Combining the three banks in one packet updates only the first bank in the +retained client. These updates are private to the owning player. + +Administrative fixture resets need a full page reload after clearing banks: +a world reconnect inside an existing WASM runtime can retain earlier map +knowledge. Ordinary gameplay only adds knowledge. + +The native area-map check uses a playfield-to-bit table and banks 471/472. +For example, Omni-1 Entertainment 705 uses bank 471 bit 16; Omni-1 Trade 710 +uses bank 472 bit 1; Borealis 800 uses bank 472 bit 11. GM stat 215 bypasses +the check, so verification uses ordinary players with that stat zero. + +Drawing an available local map disables depth buffering through +`render_t::SetRenderState`, original bbr.dll address 0x100e8b90, lifted +`sub_250E8B90`. The Direct3D7 adapter retains ZENABLE per device and applies +it on each draw. Disabling it bypasses depth comparisons and writes; restoring +it uses the previous depth contents. Clear remains independent of this switch. +W-buffering remains unsupported. The renderer regression exercises both sides +of a cleared depth plane, then restores testing to detect accidental writes. + +The local-map overlay also uses DESTCOLOR blending (factor 9); the adapter +advertises and retains it for both blend operands and maps it to GL_DST_COLOR. +Pixel regressions check enabled/disabled blending and both operands separately. + +The Arrow marker uses XYZRHW vertices without a diffuse field (FVF 0x104). +The adapter derives color and texture offsets from the actual layout and uses +opaque white when diffuse is absent, as documented by +[Microsoft's texture-argument reference](https://learn.microsoft.com/en-us/previous-versions/ms858162(v=msdn.10)). +The regression covers zero, one and two UV sets, with and without specular, +and checks both triangles of the fan. + +The public depth-buffer switches are documented by +[Microsoft](https://learn.microsoft.com/en-us/windows/win32/direct3d9/enabling-depth-buffering); +the original Direct3D7 call boundary is retained in the native evidence below. + +## Evidence and verification + +`server/map_upload_test.go` exercises all 55 uploads through owned-item use, +literal expected masks, faction/duplicate/skill rejection, high bits, prior +knowledge, repeatable maps, private delivery, SQL failures at both writes and +COMMIT, concurrent requests, lost replies and cold database recovery. + +Verification passed the full Go server/data-export suite, focused map race +tests, vet, the complete device fixture on GPU OpenGL and Chromium WebGL, +and three WebGL context-loss/restoration cycles. The published files, decoded +WASM and recorded client-source digest match. + +Actual HTTPS WASM tests verified all three starter bundles, live Entertainment +and Borealis area unlocks with the map already open, two Full Athen Shire and +two Newland City uploads, wrong-faction rejection, Arrow's effective skill +24/25 boundary, duplicate-upgrade rejection and all five upgrades. The Arrow +and player/NPC markers draw without stopping subsequent input. Twenty captured +checkpoints compare exact native banks and item identities with SQLite. +Full page reload and a cold server restart retain the learned banks, including +Clan's high bits, and keep every consumed item absent. These successful runs +have no page errors or unsupported-adapter diagnostics. + +The complete original-record audit, hashes, payloads and disassembly are in +`local/map-upload-research/catalog/`. Original client evidence and snapshots +are in `local/map-upload-research/`; renderer evidence is in its `render-native/` +directory. Live WASM screenshots, native memory reads, packet captures and +SQLite snapshots are in `local/map-upload-smoke/`. diff --git a/server/backpacks.go b/server/backpacks.go @@ -104,6 +104,9 @@ func (server *server) handleOwnedItemUse(client *worldClient, body []byte) error case 43552: return server.useClinic_locked(client, index, body) default: + if flags, supported := player.inventory.Items[index].mapUpload(); supported { + return server.uploadMap_locked(client, index, body, flags) + } if kit, supported := player.inventory.Items[index].resourceKit(); supported { return server.useResourceKit_locked(client, index, body, kit) } diff --git a/server/inventory.go b/server/inventory.go @@ -32,6 +32,8 @@ type playerInventory struct { Reclaim []reclaimItem Containers map[uint32][]ownedItem LearnedNanos []uint32 + // Native stats 470..472: display options followed by the two area bit banks. + MapFlags [3]uint32 } func (inventory playerInventory) validate() error { diff --git a/server/item_database.go b/server/item_database.go @@ -65,7 +65,9 @@ func (server *server) persistItems_locked(store itemStore) error { if !store.flush && id != store.inventoryPlayer { continue } - if _, err := tx.Exec(`UPDATE players SET credits=?1 WHERE id=?2 AND credits IS NOT ?1`, references.Credits, id); err != nil { + if _, err := tx.Exec(`UPDATE players SET credits=?1, map_options=?2, map_area_1=?3, map_area_2=?4 + WHERE id=?5 AND (credits, map_options, map_area_1, map_area_2) IS NOT (?1, ?2, ?3, ?4)`, + references.Credits, references.MapFlags[0], references.MapFlags[1], references.MapFlags[2], id); err != nil { return err } @@ -232,14 +234,14 @@ func (server *server) readItems() (itemStore, error) { return store, err } rows.Close() - rows, err = db.Query("SELECT id, credits FROM players") + rows, err = db.Query("SELECT id, credits, map_options, map_area_1, map_area_2 FROM players") if err != nil { return store, err } for rows.Next() { var id uint32 references := characterItemReferences{inventoryReferences: inventoryReferences{Slots: emptyInventorySlots()}, Equipment: emptyEquipmentSlots(), Bank: emptyItemSlots(bankCapacity)} - if err := rows.Scan(&id, &references.Credits); err != nil { + if err := rows.Scan(&id, &references.Credits, &references.MapFlags[0], &references.MapFlags[1], &references.MapFlags[2]); err != nil { rows.Close() return store, err } diff --git a/server/item_requirements.go b/server/item_requirements.go @@ -87,6 +87,13 @@ func requirementsMet(requirements []gamedata.ItemRequirement, evaluate func(game } func (character *character) meetsStatRequirement(requirement gamedata.ItemRequirement) (bool, bool) { + // Map knowledge uses intrinsic bit banks; unknown bitfield producers stay closed. + if requirement.Operator == 22 { + if requirement.Stat < 470 || requirement.Stat > 472 { + return false, false + } + return character.inventory.MapFlags[requirement.Stat-470]&uint32(requirement.Value) != 0, true + } if requirement.Operator != 0 && requirement.Operator != 1 && requirement.Operator != 2 && requirement.Operator != 24 { return false, false } diff --git a/server/item_store.go b/server/item_store.go @@ -30,6 +30,7 @@ type inventoryReferences struct { Slots map[string]*uint32 `yaml:"slots"` Reclaim []reclaimReference `yaml:"reclaim"` LearnedNanos []uint32 `yaml:"learned_nanos"` + MapFlags [3]uint32 `yaml:"map_flags,flow"` } type characterItemReferences struct { @@ -66,7 +67,7 @@ func emptyItemSlots(count uint32) map[string]*uint32 { func (inventory playerInventory) references() characterItemReferences { result := characterItemReferences{inventoryReferences: inventoryReferences{Credits: inventory.Credits, Slots: emptyInventorySlots(), - LearnedNanos: slices.Clone(inventory.LearnedNanos)}, Equipment: emptyEquipmentSlots(), Bank: emptyItemSlots(bankCapacity)} + LearnedNanos: slices.Clone(inventory.LearnedNanos), MapFlags: inventory.MapFlags}, Equipment: emptyEquipmentSlots(), Bank: emptyItemSlots(bankCapacity)} for _, item := range inventory.Items { if item.Slot >= 64 { result.Slots[fmt.Sprintf("inventory_slot_%d", item.Slot-63)] = &item.ID @@ -117,7 +118,7 @@ func referencedItems(slots map[string]*uint32, first, count uint32, records map[ } func (references characterItemReferences) inventory(records map[uint32]itemRecord, lastID uint32) (playerInventory, error) { - inventory := playerInventory{LastID: lastID, Credits: references.Credits, LearnedNanos: references.LearnedNanos} + inventory := playerInventory{LastID: lastID, Credits: references.Credits, LearnedNanos: references.LearnedNanos, MapFlags: references.MapFlags} // Named character slots map directly to the native placement numbers. names := make(map[string]uint32) for slot, name := range equipmentSlots { diff --git a/server/map_upload.go b/server/map_upload.go @@ -0,0 +1,97 @@ +package main + +import ( + "ao/server/gamedata" + "encoding/binary" + "slices" +) + +func (item ownedItem) mapUpload() ([3]uint32, bool) { + var flags [3]uint32 + definition := gamedata.ItemTemplates[item.Template] + if item.Type != 51005 || definition == nil || definition.HeaderWords[0] != item.Type || definition.Undecoded != nil || + item.Quality != *definition.Quality || itemStat(definition, 30) != 41 || itemStat(definition, 212) != 1 || itemStat(definition, 294) != 0 { + return flags, false + } + + // Admit the complete immediate map contract, including each authored use gate. + for _, section := range definition.Sections { + if section.Type == 22 && section.Actions != nil { + for _, action := range *section.Actions { + if action.Type != 3 { + return flags, false + } + } + continue + } + if section.Type != 2 || section.Subtype != 0 || section.Functions == nil { + return flags, false + } + for _, function := range *section.Functions { + if function.Target != 2 || function.TickCount != 1 || function.TickInterval != 0 || len(function.Requirements) != 0 { + return flags, false + } + var stat, mask uint32 + switch function.ID { + case 53002: + if len(function.Arguments) != 4 || *function.Arguments[1].Integer != *function.Arguments[2].Integer || *function.Arguments[3].Integer != 0 { + return flags, false + } + stat, mask = uint32(*function.Arguments[0].Integer), uint32(*function.Arguments[1].Integer) + case 53139: + if len(function.Arguments) != 2 || *function.Arguments[1].Integer < 0 || *function.Arguments[1].Integer > 31 { + return flags, false + } + stat, mask = uint32(*function.Arguments[0].Integer), 1<<uint32(*function.Arguments[1].Integer) + default: + return flags, false + } + if stat < 470 || stat > 472 { + return flags, false + } + flags[stat-470] |= mask + } + } + return flags, flags != [3]uint32{} +} + +func (server *server) uploadMap_locked(client *worldClient, index int, body []byte, flags [3]uint32) error { + player := server.characters[client.id] + item := player.inventory.Items[index] + accepted := item.Slot >= 64 && player.templateUseRequirementsMet(gamedata.ItemTemplates[item.Template]) + if accepted { + // Knowledge and consumption share the inventory transaction. OR preserves + // existing regions, including authored maps which allow re-upload. + inventory := player.inventory + for index, mask := range flags { + inventory.MapFlags[index] |= mask + } + inventory.Items = slices.Delete(slices.Clone(inventory.Items), index, index+1) + if err := server.saveInventory_locked(player, inventory); err != nil { + return err + } + } + + // Native Eat consumes one proxy charge; explicit removal frees the empty row. + reply := append([]byte(nil), body[16:]...) + binary.BigEndian.PutUint32(reply, 2) + if accepted { + binary.BigEndian.PutUint32(reply, 1) + } + if err := client.send(n3Packet(0x52526858, 50000, client.id, reply)); err != nil || !accepted { + return err + } + for index, mask := range player.inventory.MapFlags { + // StatIIR carries exactly one stat/value pair. + stats := binary.BigEndian.AppendUint32(nil, 470+uint32(index)) + stats = binary.BigEndian.AppendUint32(stats, mask) + if err := client.send(n3Packet(0x2b333d6e, 50000, client.id, stats)); err != nil { + return err + } + } + var removal []byte + for _, value := range []uint32{112, 104, item.Slot, item.Template, item.Template} { + removal = binary.BigEndian.AppendUint32(removal, value) + } + return client.send(n3Packet(0x5e477770, 50000, client.id, removal)) +} diff --git a/server/map_upload_test.go b/server/map_upload_test.go @@ -0,0 +1,297 @@ +package main + +import ( + "ao/server/gamedata" + "encoding/binary" + "fmt" + "reflect" + "slices" + "sync" + "testing" +) + +func TestMapUploadCatalogAdmitsCompleteOriginalContracts(t *testing.T) { + var admitted []uint32 + + for _, definition := range gamedata.ItemTemplates { + if definition.Quality == nil { + continue + } + item := ownedItem{Type: definition.HeaderWords[0], Template: definition.ID, Quality: *definition.Quality} + if _, supported := item.mapUpload(); supported { + admitted = append(admitted, definition.ID) + } + } + slices.Sort(admitted) + + if !slices.Equal(admitted, []uint32{116644, 116645, 116646, 116647, 116648, 116649, 116650, 116651, 116652, 116653, 116654, 116655, 116656, 116657, 116658, 116659, 116660, 116661, 116662, 116663, 116664, 116665, 116666, 116667, 116668, 116669, 116670, 116671, 116672, 116673, 116674, 116675, 116676, 116677, 116678, 116679, 116680, 116681, 116682, 116683, 116684, 116685, 116686, 116687, 116688, 116689, 116690, 116691, 116692, 116693, 116694, 116696, 116697, 143886, 151754}) { + t.Fatal("unexpected map contract", admitted) + } +} + +func newMapUploadWorld(t *testing.T, template uint32) (*server, *combatTestConn) { + t.Helper() + world, conn := newEquipmentWorld(t) + player := world.characters[1] + player.inventory.Items[0] = ownedItem{ID: 1, Type: 51005, Template: template, Quality: 1, Slot: 64, Count: 1} + player.stats.Navigation.MapNavigation = 700 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + return world, conn +} + +func TestMapUploadPersistsAuthoredMasksAndConsumesOneInstance(t *testing.T) { + for _, scenario := range []struct { + name string + template uint32 + side uint16 + before, after [3]uint32 + }{ + {"Omni starter", 116693, 2, [3]uint32{}, [3]uint32{0, 0x18c00, 0x1600403b}}, + {"Clan starter high bit", 116696, 1, [3]uint32{}, [3]uint32{0, 0x1180000e, 0xc1000000}}, + {"neutral starter", 116697, 0, [3]uint32{}, [3]uint32{0, 0x4000, 0x20001840}}, + {"Omni authored repeated bank gate", 116693, 2, [3]uint32{16, 0, 0x80000002}, [3]uint32{16, 0x18c00, 0x9600403b}}, + {"ordinary area", 116656, 0, [3]uint32{16, 1, 2}, [3]uint32{16, 0x10001, 2}}, + {"two-bank SetFlag", 116646, 0, [3]uint32{8, 1, 2}, [3]uint32{8, 5, 0x40000002}}, + {"repeatable SetFlag", 116646, 0, [3]uint32{8, 5, 0x40000002}, [3]uint32{8, 5, 0x40000002}}, + {"map without criteria", 116676, 0, [3]uint32{16, 0, 4}, [3]uint32{16, 0x80000000, 4}}, + {"repeatable Hit", 116676, 0, [3]uint32{16, 0x80000000, 4}, [3]uint32{16, 0x80000000, 4}}, + {"compass upgrade", 116694, 0, [3]uint32{4, 1, 2}, [3]uint32{20, 1, 2}}, + } { + t.Run(scenario.name, func(t *testing.T) { + world, conn := newMapUploadWorld(t, scenario.template) + player := world.characters[1] + player.appearance = player.appearance&^(3<<9) | scenario.side<<9 + player.inventory.MapFlags = scenario.before + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + + err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 64, 1)[20:]) + world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 64, 1)[20:]) + restored := newTestInventoryServer(t).characters[1].inventory + + if err != nil || restored.MapFlags != scenario.after || player.inventory.MapFlags != scenario.after || len(restored.Items) != 0 || len(world.items) != 0 || world.nextItem != 1 { + t.Fatal("map knowledge or consumed identity mismatch", err, restored) + } + if len(conn.packets) != 5 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 1 || binary.BigEndian.Uint32(conn.packets[4][29:33]) != 112 { + t.Fatal("map ACK/stat/removal ordering mismatch", conn.packets) + } + for index, value := range scenario.after { + packet := conn.packets[index+1] + if len(packet) != 40 || binary.BigEndian.Uint32(packet[16:20]) != 0x2b333d6e || binary.BigEndian.Uint32(packet[29:33]) != 470+uint32(index) || binary.BigEndian.Uint32(packet[33:37]) != value { + t.Fatal("wrong map bank update") + } + } + }) + } +} + +func TestMapUploadRejectsAuthoredRequirementsWithoutConsuming(t *testing.T) { + for _, scenario := range []struct { + name string + template uint32 + side uint16 + skill uint16 + flags [3]uint32 + }{ + {"wrong starter side", 116693, 1, 700, [3]uint32{}}, + {"starter with prior regions", 116696, 1, 700, [3]uint32{0, 0, 1}}, + {"known ordinary region", 116656, 2, 700, [3]uint32{0, 0x10000, 0}}, + {"known SetFlag region", 116691, 0, 700, [3]uint32{0, 0, 2048}}, + {"known upgrade", 116694, 0, 700, [3]uint32{16, 0, 0}}, + {"strict map skill", 116656, 2, 12, [3]uint32{}}, + {"strict upgrade skill", 116694, 0, 22, [3]uint32{}}, + } { + t.Run(scenario.name, func(t *testing.T) { + world, conn := newMapUploadWorld(t, scenario.template) + player := world.characters[1] + player.appearance = player.appearance&^(3<<9) | scenario.side<<9 + player.stats.Navigation.MapNavigation = scenario.skill + player.inventory.MapFlags = scenario.flags + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + before := player.inventory + + err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 64, 1)[20:]) + restored := newTestInventoryServer(t).characters[1].inventory + + if err != nil || len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 2 || !reflect.DeepEqual(player.inventory, before) || restored.MapFlags != before.MapFlags || !reflect.DeepEqual(restored.Items, before.Items) { + t.Fatal("rejected map changed knowledge or ownership", err, restored) + } + }) + } +} + +func TestMapUploadSQLFailureLeavesKnowledgeAndItemThenRetries(t *testing.T) { + for _, phase := range []string{"knowledge", "item", "commit"} { + t.Run(phase, func(t *testing.T) { + world, conn := newMapUploadWorld(t, 116646) + player := world.characters[1] + statement := "CREATE TRIGGER reject_map BEFORE UPDATE OF map_area_1 ON players BEGIN SELECT RAISE(FAIL, 'map flags'); END" + switch phase { + case "item": + statement = "CREATE TRIGGER reject_map BEFORE DELETE ON items BEGIN SELECT RAISE(FAIL, 'map item'); END" + case "commit": + if _, err := world.db.Exec("CREATE TABLE map_commit_failure (value INTEGER REFERENCES items(id) DEFERRABLE INITIALLY DEFERRED)"); err != nil { + t.Fatal(err) + } + statement = "CREATE TRIGGER reject_map AFTER UPDATE OF map_area_1 ON players BEGIN INSERT INTO map_commit_failure VALUES(9999); END" + } + if _, err := world.db.Exec(statement); err != nil { + t.Fatal(err) + } + + failed := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 64, 1)[20:]) + rejected := newTestInventoryServer(t).characters[1].inventory + if failed == nil || player.inventory.MapFlags != [3]uint32{} || len(player.inventory.Items) != 1 || rejected.MapFlags != [3]uint32{} || len(rejected.Items) != 1 || len(conn.packets) != 0 { + t.Fatal("failed map transaction published partial state") + } + if _, err := world.db.Exec("DROP TRIGGER reject_map"); err != nil { + t.Fatal(err) + } + err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 64, 2)[20:]) + restored := newTestInventoryServer(t).characters[1].inventory + + if err != nil || restored.MapFlags != [3]uint32{0, 4, 0x40000000} || len(restored.Items) != 0 { + t.Fatal("map transaction retry failed", err, restored) + } + }) + } +} + +func TestMapUploadConcurrentAndLostReplyConsumeExactlyOnce(t *testing.T) { + for _, lost := range []bool{false, true} { + t.Run(map[bool]string{false: "concurrent", true: "lost reply"}[lost], func(t *testing.T) { + world, _ := newMapUploadWorld(t, 116646) + client := world.clients[1] + if lost { + client.conn = &failingCombatConn{} + } + request := backpackUseRequest(1, 64, 1)[20:] + + var jobs sync.WaitGroup + for range 2 { + jobs.Go(func() { world.handleOwnedItemUse(client, request) }) + } + jobs.Wait() + restored := newTestInventoryServer(t).characters[1].inventory + + if restored.MapFlags != [3]uint32{0, 4, 0x40000000} || len(restored.Items) != 0 || world.nextItem != 1 { + t.Fatal("map use was lost or duplicated", restored) + } + }) + } +} + +func TestMapUploadEveryCatalogEntryThroughOwnedUse(t *testing.T) { + for _, scenario := range []struct { + template uint32 + side uint16 + flags [3]uint32 + }{ + {116644, 0, [3]uint32{0, 0x00000001, 0}}, + {116645, 0, [3]uint32{0, 0x00000002, 0x80000000}}, + {116646, 0, [3]uint32{0, 0x00000004, 0x40000000}}, + {116647, 0, [3]uint32{0, 0x00000008, 0}}, + {116648, 0, [3]uint32{0, 0x00000040, 0}}, + {116649, 0, [3]uint32{0, 0x00000080, 0}}, + {116650, 0, [3]uint32{0, 0x00000100, 0}}, + {116651, 0, [3]uint32{0, 0x00000200, 0}}, + {116652, 0, [3]uint32{0, 0x00000800, 0x10000000}}, + {116653, 0, [3]uint32{0, 0x00002000, 0}}, + {116654, 0, [3]uint32{0, 0x00004000, 0}}, + {116655, 0, [3]uint32{0, 0x00020000, 0}}, + {116656, 0, [3]uint32{0, 0x00010000, 0}}, + {116657, 0, [3]uint32{0, 0x00100000, 0}}, + {116658, 0, [3]uint32{0, 0x00200000, 0}}, + {116659, 0, [3]uint32{0, 0x00800000, 0}}, + {116660, 0, [3]uint32{0, 0x01000000, 0x01000000}}, + {116661, 0, [3]uint32{0, 0x04000000, 0}}, + {116662, 0, [3]uint32{0, 0x20000000, 0}}, + {116663, 0, [3]uint32{0, 0x00000010, 0}}, + {116664, 0, [3]uint32{0, 0x00000020, 0}}, + {116665, 0, [3]uint32{0, 0x00000400, 0}}, + {116666, 0, [3]uint32{0, 0x00001000, 0}}, + {116667, 0, [3]uint32{0, 0, 0x00001000}}, + {116668, 0, [3]uint32{0, 0x00008000, 0x02000000}}, + {116669, 0, [3]uint32{0, 0x00040000, 0}}, + {116670, 0, [3]uint32{0, 0x00080000, 0}}, + {116671, 0, [3]uint32{0, 0x00400000, 0}}, + {116672, 0, [3]uint32{0, 0x02000000, 0}}, + {116673, 0, [3]uint32{0, 0x08000000, 0}}, + {116674, 0, [3]uint32{0, 0x10000000, 0}}, + {116675, 0, [3]uint32{0, 0x40000000, 0}}, + {116676, 0, [3]uint32{0, 0x80000000, 0}}, + {116677, 0, [3]uint32{0, 0, 0x00000001}}, + {116678, 0, [3]uint32{0, 0, 0x00000004}}, + {116679, 0, [3]uint32{0, 0, 0x00000010}}, + {116680, 0, [3]uint32{0, 0, 0x00000040}}, + {116681, 0, [3]uint32{0, 0, 0x00000100}}, + {116682, 0, [3]uint32{0, 0, 0x00000400}}, + {116683, 0, [3]uint32{0x00000001, 0, 0}}, + {116684, 0, [3]uint32{0x00000002, 0, 0}}, + {116685, 0, [3]uint32{0x00000004, 0, 0}}, + {116686, 0, [3]uint32{0, 0, 0x00000002}}, + {116687, 0, [3]uint32{0, 0, 0x00000008}}, + {116688, 0, [3]uint32{0, 0, 0x00000020}}, + {116689, 0, [3]uint32{0, 0, 0x00000080}}, + {116690, 0, [3]uint32{0, 0, 0x00000200}}, + {116691, 0, [3]uint32{0, 0, 0x00000800}}, + {116692, 0, [3]uint32{0x00000008, 0, 0}}, + {116693, 2, [3]uint32{0, 0x00018c00, 0x1600403b}}, + {116694, 0, [3]uint32{0x00000010, 0, 0}}, + {116696, 1, [3]uint32{0, 0x1180000e, 0xc1000000}}, + {116697, 0, [3]uint32{0, 0x00004000, 0x20001840}}, + {143886, 0, [3]uint32{0, 0, 0x08000000}}, + {151754, 0, [3]uint32{0, 0, 0x20000000}}, + } { + t.Run(fmt.Sprint(scenario.template), func(t *testing.T) { + world, _ := newMapUploadWorld(t, scenario.template) + player := world.characters[1] + player.appearance = player.appearance&^(3<<9) | scenario.side<<9 + + err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 64, 1)[20:]) + restored := newTestInventoryServer(t).characters[1].inventory + + if err != nil || restored.MapFlags != scenario.flags || player.inventory.MapFlags != scenario.flags || len(restored.Items) != 0 { + t.Fatal("authored map upload failed", scenario.template, err, restored) + } + }) + } +} + +func TestMapUploadEffectiveSkillBoundaryAndOwnerOnlyDelivery(t *testing.T) { + for _, scenario := range []struct { + name string + template uint32 + raw uint16 + accepted bool + }{ + {"area threshold", 116656, 12, false}, {"area above", 116656, 13, true}, + {"upgrade threshold", 116694, 22, false}, {"upgrade above", 116694, 23, true}, + } { + t.Run(scenario.name, func(t *testing.T) { + world, conn := newMapUploadWorld(t, scenario.template) + player := world.characters[1] + player.stats.Navigation.MapNavigation = scenario.raw + observer := &combatTestConn{} + world.characters[2] = &character{id: 2, health: 100, playfield: player.playfield} + world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true} + + err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 64, 1)[20:]) + + if err != nil || (len(player.inventory.Items) == 0) != scenario.accepted || len(observer.packets) != 0 || (binary.BigEndian.Uint32(conn.packets[0][29:33]) == 1) != scenario.accepted { + t.Fatal("effective map skill boundary or private delivery changed", err, player.inventory) + } + }) + } +} diff --git a/server/target_protocol_test.go b/server/target_protocol_test.go @@ -113,7 +113,7 @@ initialized: if hex.EncodeToString(npc[60:89]) != "000005cb0b456469746564204e50430000000000000000000000000007" { t.Fatalf("target NPC appearance, name and new stats: %x", npc[60:89]) } - if hex.EncodeToString(full[57:105]) != "000003f100017a600000003600000001000000340000000000000039000000000000015e000005aa000000ec00000000" { + if hex.EncodeToString(full[57:105]) != "000003f1000186330000003600000001000000340000000000000039000000000000015e000005aa000000ec00000000" { t.Fatalf("target seventh list and initial progression/insurance stats: %x", full[57:105]) } } diff --git a/server/weapon_stats.go b/server/weapon_stats.go @@ -27,6 +27,8 @@ func (character *character) effectiveStat(stat uint32) (int32, bool) { return int32(character.level), true case 60, 368: return int32(character.profession), true + case 470, 471, 472: + return int32(character.inventory.MapFlags[stat-470]), true } stats := character.baseStats() for _, field := range stats.trainingStats() { diff --git a/server/world.go b/server/world.go @@ -201,6 +201,9 @@ func fullCharacterPacket(character *character) []byte { lowerXP, upperXP := character.experienceBounds() stats := [][2]uint32{{54, uint32(character.level)}, {52, lowerXP + character.experience}, {57, lowerXP}, {350, upperXP}, {236, max(lowerXP, character.insuredExperience)}} stats = append(stats, character.baseStats().nativeStats()...) + for index, flags := range character.inventory.MapFlags { + stats = append(stats, [2]uint32{470 + uint32(index), flags}) + } stats = append(stats, [2]uint32{4, uint32(character.appearance >> 4 & 7)}, [2]uint32{60, uint32(max(1, character.profession))}, diff --git a/server/world.sql b/server/world.sql @@ -128,7 +128,10 @@ CREATE TABLE IF NOT EXISTS characters ( CREATE UNIQUE INDEX IF NOT EXISTS player_login_names ON characters(name COLLATE NOCASE) WHERE length(password_hash)>0; CREATE TABLE IF NOT EXISTS players ( id INTEGER PRIMARY KEY REFERENCES characters(id) ON DELETE CASCADE CHECK (id BETWEEN 1 AND 999999), - credits INTEGER NOT NULL DEFAULT 0 + credits INTEGER NOT NULL DEFAULT 0, + map_options INTEGER NOT NULL DEFAULT 0, + map_area_1 INTEGER NOT NULL DEFAULT 0, + map_area_2 INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE IF NOT EXISTS buddies ( player_id INTEGER NOT NULL REFERENCES players(id) ON DELETE CASCADE,