Code Quality Standards (Q1–Q14)

Every byte-matching submission must compile cleanly to the original GoG 1.23 machine code and meet Project Aesir's C++ readability, provenance, and canonical header standards. Rules marked REFUSE reject submissions with zero strikes and an exact fix hint; rules marked FLAG accept the match and record tracked rework debt.

schema: aesir-standards/1 standards_version: 2026-12-05.1 grace_window: 24h strike-free on new kit releases machine API: GET /api/v1/standards
Q1Q2Q3Q4 Q5Q6Q7Q8 Q9Q10Q11Q12 Q13Q14

Q1No codegen steering

REFUSE

Bans _ReadWriteBarrier, #pragma optimize, #pragma intrinsic, #pragma function, volatile locals, and synthetic __declspec(noinline).

Avoid
#pragma optimize("g", off)
volatile int tmp = x;
Prefer
int tmp = x;
Fix hint: Remove compiler-steering pragmas, volatile locals, and artificial __declspec(noinline); express the original C++ control flow and types instead. Library-header volatile cited with file:line routes to Q14 debt.

Q2No inline assembly

REFUSE

Bans 32-bit inline __asm / _asm / __emit and hand-written .asm outside third_party/ and config/standards_exceptions.json.

Avoid
__asm { mov eax, ecx }
Prefer
return value;
Fix hint: Replace __asm / _asm / __emit blocks with portable C++ or standard MSVC intrinsics (e.g., __debugbreak()).

Q3No decompiler leftovers

REFUSE

Bans Ghidra/decompiler artifacts: undefined1/2/4/8, CONCAT/SUB/ZEXT, param_N, uVar/iVar/pVar, hex stack locals (local_10), and synthetic in_EAX register parameters.

Avoid
undefined4 FUN_00401000(int param_1, int in_EAX) { int local_10 = param_1; return local_10; }
Prefer
int ComputeBonus(int base_level) { int bonus = base_level; return bonus; }
Fix hint: Replace decompiler placeholder types and variable names with meaningful C++ types and names. For file-local custom-register callees (in_EAX), use a coff_tu multi-function packet instead of register hacks. Renamed-decompiler ('Geiger-1') shapes are tracked as Q3_GEIGER1 debt.

Q4Fields by name

REFUSE

Bans raw pointer-offset arithmetic (*(int*)((char*)this + 0x48)) on types defined in shared headers (include/nwn2/).

Avoid
int hp = *(int*)((char*)this + 0x48);
Prefer
int hp = this->m_nCurrentHitPoints;
Fix hint: Access known struct/class members by their named field in include/nwn2/. Unmapped fields on known types are flagged as Q4 debt until added in a Header Wave.

Q5Shared types only

REFUSE

Bans private local redefinitions of structs/classes already published in shared headers (include/nwn2/).

Avoid
struct CExoString { char* m_sString; unsigned int m_nBufferLength; };
Prefer
#include "nwn2/CExoString.h"
Fix hint: Include the canonical shared header from include/nwn2/ instead of redefining the struct locally. Unlanded types are tracked as Q5 debt.

Q6One name, one address, one definition (binary-scoped)

REFUSE

Within each binary_id, every function or global symbol name binds to exactly one RVA and is defined in one unit. Multiple alias names may share one RVA (ICF), never one name on two RVAs.

Avoid
// Defining CNWSCreature::GetLevel at two different RVAs in nwn2main
Prefer
// Distinct binary-scoped bindings: (nwn2main, sym)->rva1, (nwn2server, sym)->rva2
Fix hint: Check symbols/<binary_id>.json.gz for an existing binding and reuse or disambiguate the symbol name.

Q7Matched in its real file

REFUSE

Canonical submissions must compile byte-exact inside their real translation unit without breaking any neighboring matched function.

Avoid
// Standalone file that perturbs neighbor float pool when merged
Prefer
// Canonical TU passing match_check.py --tu-manifest with 0 neighbor regressions
Fix hint: Verify inside the canonical TU packet using nwn2check and resolve any string/float pool or intra-TU inlining interaction.

Q8Real translation units

REFUSE

Translation units mirror original source files with a single compiler flag set per unit (same unit_flags island).

Avoid
// Mixing vc71 FaceFX and vc8 gameplay functions in one TU
Prefer
// Functions sharing one compiler island and flag set within <= 256 KB span
Fix hint: Split mixed-flag or cross-island functions into separate translation units.

Q9Real names with provenance

FLAG

Symbol names carry provenance tags (RTTI, STRING, SWIG_EXPORT, TWIN, GUESS:high|medium|low); FUN_<addr> is accepted as rework debt.

Avoid
void FUN_0051a040(); // no provenance
Prefer
void CNWSCreature::UpdateCombatRound(); // provenance: RTTI
Fix hint: Attach verified RTTI, string, SWIG export, or twin provenance when renaming FUN_<addr>.

Q10Clean comments

REFUSE

Bans AI model/tool/pipeline names (Claude, GPT, Opus, Gemini, DeepSeek), emails, local paths, and pack/checkpoint IDs in comments.

Avoid
// Matched by Claude Opus from /home/user/scratch/pack_123
Prefer
// Returns the modified attack bonus for the active weapon hand.
Fix hint: Strip all model/tool/pipeline references, local filesystem paths, emails, and internal IDs from comments.

Q11Builds clean

REFUSE

Must compile with zero warnings at /W3 and match repository formatting.

Avoid
int f(unsigned x) { if (x < 0) return 0; }
Prefer
int f(unsigned x) { return (int)x; }
Fix hint: Resolve all /W3 compiler warnings and format according to repository rules.

Q12Third-party code vendored

REFUSE

Public open-source libraries (zlib, FreeType, libcurl, TinyXML, minizip/LZMA) live unmodified under third_party/ with checksums; game patches are reviewed diffs.

Avoid
// Hand-pasting modified zlib inflate into src/nwn2main/
Prefer
// Linking vendored third_party/zlib-1.2.3/inflate.c
Fix hint: Use the vendored upstream source under third_party/ and keep any Obsidian edits as reviewed diffs.

Q13Second-executable cross-check

FLAG

Shared engine source should match sibling binaries (nwn2main, nwn2main_amdxp, nwn2server, NWN2RulesLib); bonus when identical, flagged when divergent.

Avoid
// Matching only nwn2main when nwn2main_amdxp differs trivially
Prefer
// Identical C++ matching both nwn2main (/arch:SSE2) and nwn2main_amdxp (x87)
Fix hint: Check sibling targets via Lane A/B twin porting and guard genuine client/server layout deltas with #ifdef AESIR_TARGET_SERVER.

Q14Semantics-neutral shaping

FLAG

Tracks redundant parens, forced statement order, cited library volatile, throw()/__declspec(nothrow) annotations, and hand-written compiler-generated helpers declared via // Q14:.

Avoid
// Unexplained redundant temporaries
Prefer
// Q14: VC8 register allocation requires explicit local copy before branch
Fix hint: Document unavoidable semantics-neutral compiler shaping with a concise // Q14: note.

Kit Rollouts, 24-Hour Grace Windows & Exceptions

Whenever a new YYYY-MM-DD.N contributor kit tightens a rule or introduces a new Header Wave, the coordinator enforces a 24-hour strike-free grace window (grace_until = effective_at + 24h). Submissions tripping newly tightened rules during the grace window return refused_standards with counts_as_strike: false and grace_protected: true while keeping the active claim open. Claims opened before effective_at automatically downgrade newly landed Q5 shared types to non-refusal flags. Documented edge-case allowlists live in config/standards_exceptions.json.