Update rules, fixes

This commit is contained in:
Christian Semmler 2023-12-12 09:47:06 -05:00
parent a134a8b9e6
commit 9dc982f901
19 changed files with 99 additions and 59 deletions

View File

@ -23,6 +23,7 @@ jobs:
python3 tools/ncc/ncc.py \
--clang-lib ${{ env.LLVM_PATH }}/lib/libclang.so \
--style tools/ncc/ncc.style \
--skip tools/ncc/skip.yaml
--definition WINAPI FAR HWND__=HWND \
--include util \
--path LEGO1

View File

@ -22,9 +22,9 @@ class AmbulanceMissionState : public LegoState {
return !strcmp(p_name, AmbulanceMissionState::ClassName()) || LegoState::IsA(p_name);
}
inline MxU16 GetColor(MxU8 id)
inline MxU16 GetColor(MxU8 p_id)
{
switch (id) {
switch (p_id) {
case 1:
return m_color1;
case 2:

View File

@ -11,8 +11,8 @@ GasStationState::GasStationState()
m_unk0x1e = 0;
m_unk0x20 = 0;
undefined4* unk = m_unk0x08;
unk[0] = -1;
unk[1] = -1;
unk[2] = -1;
undefined4* unk0x08 = m_unk0x08;
unk0x08[0] = -1;
unk0x08[1] = -1;
unk0x08[2] = -1;
}

View File

@ -6,15 +6,15 @@ DECOMP_SIZE_ASSERT(GifMap, 0x08);
DECOMP_SIZE_ASSERT(GifManagerBase, 0x14);
DECOMP_SIZE_ASSERT(GifManager, 0x30);
GifMapEntry* DAT_100f0100;
GifMapEntry* g_unk0x100f0100;
// FUNCTION: LEGO1 0x10001cc0
GifMapEntry* GifMap::FindNode(const char*& string)
GifMapEntry* GifMap::FindNode(const char*& p_string)
{
GifMapEntry* ret = m_unk0x4;
GifMapEntry* current = ret->m_parent;
while (current != DAT_100f0100) {
if (strcmp(current->m_key, string) <= 0) {
while (current != g_unk0x100f0100) {
if (strcmp(current->m_key, p_string) <= 0) {
ret = current;
current = current->m_right;
}

View File

@ -27,13 +27,13 @@ struct GifMapEntry {
class GifMap {
public:
GifMapEntry* FindNode(const char*& string);
GifMapEntry* FindNode(const char*& p_string);
inline GifData* Get(const char* string)
inline GifData* Get(const char* p_string)
{
GifData* ret = NULL;
GifMapEntry* entry = FindNode(string);
if (((m_unk0x4 == entry || strcmp(string, entry->m_key) > 0) ? m_unk0x4 : entry) != entry)
GifMapEntry* entry = FindNode(p_string);
if (((m_unk0x4 == entry || strcmp(p_string, entry->m_key) > 0) ? m_unk0x4 : entry) != entry)
ret = entry->m_value;
return ret;
}
@ -48,7 +48,7 @@ class GifManagerBase {
// STUB: LEGO1 0x1005a310
virtual ~GifManagerBase() {} // vtable+00
inline GifData* Get(const char* name) { return m_unk0x8.Get(name); }
inline GifData* Get(const char* p_name) { return m_unk0x8.Get(p_name); }
protected:
undefined4 m_unk0x0;

View File

@ -21,7 +21,7 @@ class HelicopterState : public LegoState {
return !strcmp(p_name, HelicopterState::ClassName()) || LegoState::IsA(p_name);
}
inline void SetUnknown8(undefined4 p_unk8) { m_unk0x8 = p_unk8; }
inline void SetUnknown8(undefined4 p_unk0x8) { m_unk0x8 = p_unk0x8; }
protected:
undefined4 m_unk0x8;

View File

@ -55,7 +55,7 @@ class InfocenterState : public LegoState {
undefined4 unk13;
*/
undefined pad[0x70];
undefined m_pad[0x70];
MxU32 m_buffer[7]; // 0x78
};

View File

@ -37,7 +37,7 @@ void IslePathActor::VTable0xd8()
// FUNCTION: LEGO1 0x1001a200
IslePathActor::IslePathActor()
{
this->m_pLegoWorld = NULL;
this->m_world = NULL;
this->m_unk0x13c = 6.0;
this->m_unk0x15c = 1.0;
this->m_unk0x158 = 0;
@ -62,7 +62,7 @@ void IslePathActor::VTable0xe4()
}
// STUB: LEGO1 0x1001b2a0
void IslePathActor::VTable0xe8(MxU32 p_1, MxBool p_2, MxU8 p_3)
void IslePathActor::VTable0xe8(MxU32, MxBool, MxU8)
{
// TODO
}

View File

@ -36,14 +36,14 @@ class IslePathActor : public LegoPathActor {
virtual void VTable0xdc(); // vtable+0xdc
virtual void VTable0xe0(); // vtable+0xe0
virtual void VTable0xe4(); // vtable+0xe4
virtual void VTable0xe8(MxU32 p_1, MxBool p_2, MxU8 p_3); // vtable+0xe8
virtual void VTable0xe8(MxU32, MxBool, MxU8); // vtable+0xe8
virtual void VTable0xec(); // vtable+0xec
inline void SetWorld(LegoWorld* p_world) { m_pLegoWorld = p_world; }
inline LegoWorld* GetWorld() { return m_pLegoWorld; }
inline void SetWorld(LegoWorld* p_world) { m_world = p_world; }
inline LegoWorld* GetWorld() { return m_world; }
private:
LegoWorld* m_pLegoWorld; // 0x154
LegoWorld* m_world; // 0x154
MxFloat m_unk0x158;
MxFloat m_unk0x15c;
};

View File

@ -8,7 +8,7 @@ class Lego3DView {
inline ViewManager* GetViewManager() { return this->m_viewManager; }
private:
char unknown[0x88];
char m_pad[0x88];
ViewManager* m_viewManager;
};

View File

@ -10,15 +10,15 @@ MxFloat LegoActor::VTable0x50()
}
// FUNCTION: LEGO1 0x10002cd0
void LegoActor::VTable0x54(MxFloat p_unk)
void LegoActor::VTable0x54(MxFloat p_unk0x68)
{
m_unk0x68 = p_unk;
m_unk0x68 = p_unk0x68;
}
// FUNCTION: LEGO1 0x10002ce0
void LegoActor::VTable0x58(MxFloat p_unk)
void LegoActor::VTable0x58(MxFloat p_unk0x70)
{
m_unk0x70 = p_unk;
m_unk0x70 = p_unk0x70;
}
// FUNCTION: LEGO1 0x10002cf0
@ -34,9 +34,9 @@ undefined LegoActor::VTable0x60()
}
// FUNCTION: LEGO1 0x10002d10
void LegoActor::VTable0x64(undefined p_unk)
void LegoActor::VTable0x64(undefined p_unk0x74)
{
m_unk0x74 = p_unk;
m_unk0x74 = p_unk0x74;
}
// End header

View File

@ -23,12 +23,12 @@ class LegoActor : public LegoEntity {
return !strcmp(p_name, LegoActor::ClassName()) || LegoEntity::IsA(p_name);
}
virtual MxFloat VTable0x50(); // vtable+0x50
virtual void VTable0x54(MxFloat p_unk); // vtable+0x54
virtual void VTable0x58(MxFloat p_unk); // vtable+0x58
virtual MxFloat VTable0x5c(); // vtable+0x5c
virtual undefined VTable0x60(); // vtable+0x60
virtual void VTable0x64(undefined p_unk); // vtable+0x64
virtual MxFloat VTable0x50(); // vtable+0x50
virtual void VTable0x54(MxFloat p_unk0x68); // vtable+0x54
virtual void VTable0x58(MxFloat p_unk0x70); // vtable+0x58
virtual MxFloat VTable0x5c(); // vtable+0x5c
virtual undefined VTable0x60(); // vtable+0x60
virtual void VTable0x64(undefined p_unk0x74); // vtable+0x64
private:
MxFloat m_unk0x68;

View File

@ -4,9 +4,9 @@
int g_legoAnimationManagerConfig = 1;
// FUNCTION: LEGO1 0x1005eb50
void LegoAnimationManager::configureLegoAnimationManager(int param_1)
void LegoAnimationManager::configureLegoAnimationManager(MxS32 p_legoAnimationManagerConfig)
{
g_legoAnimationManagerConfig = param_1;
g_legoAnimationManagerConfig = p_legoAnimationManagerConfig;
}
// STUB: LEGO1 0x1005eb60
@ -28,7 +28,7 @@ void LegoAnimationManager::Init()
}
// STUB: LEGO1 0x1005f6d0
void LegoAnimationManager::FUN_1005f6d0(MxBool p)
void LegoAnimationManager::FUN_1005f6d0(MxBool)
{
// TODO
}

View File

@ -26,9 +26,9 @@ class LegoAnimationManager : public MxCore {
return !strcmp(p_name, ClassName()) || MxCore::IsA(p_name);
}
void FUN_1005f6d0(MxBool p);
void FUN_1005f6d0(MxBool);
__declspec(dllexport) static void configureLegoAnimationManager(int param_1);
__declspec(dllexport) static void configureLegoAnimationManager(MxS32 p_legoAnimationManagerConfig);
private:
void Init();

View File

@ -29,27 +29,27 @@ void LegoBackgroundColor::SetValue(const char* p_colorString)
if (!videomanager || !p_colorString)
return;
float converted_r, converted_g, converted_b;
float convertedR, convertedG, convertedB;
char* colorStringCopy = strcpy(new char[strlen(p_colorString) + 1], p_colorString);
char* colorStringSplit = strtok(colorStringCopy, g_delimiter);
if (!strcmp(colorStringSplit, g_set)) {
colorStringSplit = strtok(0, g_delimiter);
if (colorStringSplit)
h = (float) (atoi(colorStringSplit) * 0.01);
m_h = (float) (atoi(colorStringSplit) * 0.01);
colorStringSplit = strtok(0, g_delimiter);
if (colorStringSplit)
s = (float) (atoi(colorStringSplit) * 0.01);
m_s = (float) (atoi(colorStringSplit) * 0.01);
colorStringSplit = strtok(0, g_delimiter);
if (colorStringSplit)
v = (float) (atoi(colorStringSplit) * 0.01);
m_v = (float) (atoi(colorStringSplit) * 0.01);
ConvertHSVToRGB(this->h, this->s, this->v, &converted_r, &converted_g, &converted_b);
videomanager->SetSkyColor(converted_r, converted_g, converted_b);
ConvertHSVToRGB(m_h, m_s, m_v, &convertedR, &convertedG, &convertedB);
videomanager->SetSkyColor(convertedR, convertedG, convertedB);
}
else if (!strcmp(colorStringSplit, g_reset)) {
ConvertHSVToRGB(this->h, this->s, this->v, &converted_r, &converted_g, &converted_b);
videomanager->SetSkyColor(converted_r, converted_g, converted_b);
ConvertHSVToRGB(m_h, m_s, m_v, &convertedR, &convertedG, &convertedB);
videomanager->SetSkyColor(convertedR, convertedG, convertedB);
}
delete[] colorStringCopy;

View File

@ -11,9 +11,9 @@ class LegoBackgroundColor : public MxVariable {
virtual void SetValue(const char* p_colorString) override;
private:
float h;
float s;
float v;
float m_h;
float m_s;
float m_v;
};
#endif // LEGOBACKGROUNDCOLOR_H

View File

@ -367,6 +367,7 @@ def __init__(self):
self.args = None
self._style_file = None
self.file_exclusions = None
self._skip_file = None
self.parser = argparse.ArgumentParser(
prog="ncc.py",
@ -407,6 +408,11 @@ def __init__(self):
"matches a specified pattern according to the rules used by "
"the Unix shell")
self.parser.add_argument('--skip', '-s', dest="skip_file",
help="Read list of items to ignore during the check. "
"User can use the skip file to specify character sequences that should "
"be ignored by ncc")
# self.parser.add_argument('--exclude-dir', dest='exclude_dir', help="Skip the directories"
# "matching the pattern specified")
@ -425,6 +431,11 @@ def parse_cmd_line(self):
sys.stderr.write("Style file '{}' not found!\n".format(self._style_file))
sys.exit(1)
if self.args.skip_file:
self._skip_file = self.args.skip_file
if not os.path.exists(self._skip_file):
sys.stderr.write("Skip file '{}' not found!\n".format(self._skip_file))
def dump_all_rules(self):
print("----------------------------------------------------------")
print("{:<35} | {}".format("Rule Name", "Pattern"))
@ -432,6 +443,24 @@ def dump_all_rules(self):
for (key, value) in default_rules_db.items():
print("{:<35} : {}".format(key, value.pattern_str))
class SkipDb(object):
def __init__(self, skip_file=None):
self.__skip_db = {}
if skip_file:
self.build_skip_db(skip_file)
def build_skip_db(self, skip_file):
with open(skip_file) as stylefile:
style_rules = yaml.safe_load(stylefile)
for (skip_string, skip_comment) in style_rules.items():
self.__skip_db[skip_string] = skip_comment
def check_skip_db(self, input_query):
if input_query in self.__skip_db.keys():
return 1
else:
return 0
class RulesDb(object):
def __init__(self, style_file=None):
@ -491,9 +520,10 @@ def get_rule(self, rule_name):
class Validator(object):
def __init__(self, rule_db, filename, options):
def __init__(self, rule_db, filename, options, skip_db=None):
self.filename = filename
self.rule_db = rule_db
self.skip_db = skip_db
self.options = options
self.node_stack = AstNodeStack()
@ -550,6 +580,10 @@ def evaluate(self, node):
if not self.rule_db.is_rule_enabled(node.kind):
return 0
# If the pattern is in the skip list, ignore it
if self.skip_db.check_skip_db(node.displayname):
return 0
rule_name = self.rule_db.get_rule_names(node.kind)
rule = self.rule_db.get_rule(rule_name)
if rule.evaluate(node, self.node_stack.peek()) is False:
@ -598,19 +632,22 @@ def do_validate(options, filename):
""" Creating the rules database """
rules_db = RulesDb(op._style_file)
""" Creating the skip database """
skip_db = SkipDb(op._skip_file)
""" Check the source code against the configured rules """
errors = 0
for path in op.args.path:
if os.path.isfile(path):
if do_validate(op, path):
v = Validator(rules_db, path, op)
v = Validator(rules_db, path, op, skip_db)
errors += v.validate()
elif os.path.isdir(path):
for (root, subdirs, files) in os.walk(path):
for filename in files:
path = root + '/' + filename
if do_validate(op, path):
v = Validator(rules_db, path, op)
v = Validator(rules_db, path, op, skip_db)
errors += v.validate()
if not op.args.recurse:

View File

@ -1,9 +1,9 @@
ClassName: '^[A-Z][a-zA-Z0-9]+$'
CppMethod: '^operator|^FUN_[a-f0-9]{8}$|^VTable0x[a-f0-9]{1,4}$|^(?!VTable).*[A-Z][a-zA-Z0-9]+$'
CppMethod: '^operator|^FUN_[a-f0-9]{8}$|^VTable0x[a-f0-9]{1,8}$|^(?!VTable)[A-Z][a-zA-Z0-9]+$'
# EnumConstantName
EnumName: '^\(unnamed|^[A-Z][a-zA-Z0-9]+$'
FunctionName: '^operator|^FUN_[a-f0-9]{8}$|^VTable0x[a-f0-9]{1,4}$|^(?!VTable).*[A-Z][a-zA-Z0-9]+$'
ParameterName: '^p_(unk0x[a-f0-9]{1,4}$|(?!unk).*[a-z][a-zA-Z0-9]*)$|^$'
FunctionName: '^operator|^FUN_[a-f0-9]{8}$|^VTable0x[a-f0-9]{1,8}$|^(?!VTable)[A-Z][a-zA-Z0-9]+$'
ParameterName: '^p_(unk0x[a-f0-9]{1,8}$|(?!unk)[a-z][a-zA-Z0-9]*)$|^$'
StructName: '^\(anon|^\(unnamed|^[A-Z][a-zA-Z0-9]+$'
TypedefName: '^[A-Z][a-zA-Z0-9]+$'
UnionName: '^\(anon|^[A-Z][a-zA-Z0-9]+$'
@ -18,4 +18,4 @@ VariableName:
Integer: ''
Bool: ''
Pointer: ''
Pattern: '^(unk0x[a-f0-9]{1,4}$|(?!unk).*[a-z][a-zA-Z0-9]*)$'
Pattern: '^(unk0x[a-f0-9]{1,8}$|(?!unk)[a-z][a-zA-Z0-9]*)$'

2
tools/ncc/skip.yaml Normal file
View File

@ -0,0 +1,2 @@
configureLegoAnimationManager(MxS32): 'DLL exported function'