Skip to content

Commit 5d5f73f

Browse files
committed
added rough outline of contribution guidelines and removed accidental test cout
1 parent b206978 commit 5d5f73f

2 files changed

Lines changed: 62 additions & 21 deletions

File tree

CONTRIBUTING.md

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,79 @@ Also, please consider adding your name and github in the vmaware.hpp file and th
88

99

1010
## Translations
11-
If you're making translations, please make sure that you actually speak the language, and you have the intention to be as accurate as possible.
12-
13-
What you SHOULDN'T translate are:
14-
- text that's in a codeblock
15-
- text in images
16-
- text of usernames
17-
- code
18-
- and other stuff that should obviously not be translated.
11+
If you're making translations, please make sure that you have the intention to be as accurate as possible. If you're unsure which parts should be translated or not, you can use the other translated files as a reference to guide you.
1912

2013
Using translation software like google translate is allowed, but only if you cross-check between the english and translation version to verify if it's done correctly.
2114

2215
The README is quite big, so this is quite an effort. I'm sure you have better thing to do in your life but if you can do this, it would be greatly appreciated :)
2316

2417

2518
## Code contributions
26-
If you're making code changes to the cli or header file, we have a useful script at `auxiliary/updater.py` that will update:
27-
- the section line numbers in the header banner
28-
- the date of the update
29-
- and the library documentation for technique links
30-
31-
It's highly recommended to use this script before sending the PR so that all the above don't have to be manually updated, which can be time consuming and can potentially creep in some human errors.
19+
The general rules are:
20+
- Keep it C++11 compatible, this is extremely important
21+
- Use snake_case
22+
- Be as simple as possible
23+
- Prefer readability over aggressive optimisations (especially intrinsics)
24+
- Keep indentations at a minimum
25+
- Don't create huge one-liners, try to break down statements line by line
26+
- Write as few lines as possible for what you're trying to achieve
27+
- Document your code and intentions very clearly, but don't overdo them for very obvious code.
28+
- Avoid `std::function`, `std::shared_ptr`, `std::bind`, `std::list`, or very obscure C++ features.
29+
- Indent size should be 4 spaces
30+
31+
There are other formatting rules, which will be covered with a demonstration:
32+
33+
```cpp
34+
int main() {
35+
const u32 number = 10; // 1. use const whenever it should be used.
36+
// 2. use the rust integral type convention from 8 to 64 (i.e. i8, u16, u64, etc...)
37+
// 3. keep the names as simple and clear as possible, don't call it "n", call it "number".
38+
// Try to name the variables into something that can universally be discerned by anybody,
39+
// Make sure it's also context-aware and should make sense. Calling it "tmp" is also fine.
40+
// Consistency is also key in this aspect, don't do "u32 number = find_num()", do find_number().
41+
42+
if (number >= 54) { // 4. avoid magic numbers, put a comment or make a constexpr variable prior to using it,
43+
something(); // preferably the latter.
44+
} else if (number) { // 5. make the if, else if, and else statement lines the same without breaking lines, so don't do:
45+
something_else(); // if ()
46+
} // {
47+
// something();
48+
// }
49+
// else
50+
// {
51+
// something_else();
52+
// }
53+
//
54+
// try to follow as shown in this actual demonstration.
55+
56+
if (
57+
((number % 4) == 0) && // 6. use separate lines for each statement of a condition check. While this might look ok
58+
(number > 50) && // on a single line, in practice your conditions will most likely not be as short and
59+
(number < 100) // and simple as this. Try to avoid multiple condition checks in a single line for simplicity.
60+
) {
61+
something()
62+
}
63+
64+
65+
for (u8 i = 0; i < number; i++) { // 6. Be as simple as possible without using fancy features like iterators if it's not necessary.
66+
something();
67+
}
68+
69+
// Other rules will be added in the future, this is just a rough guideline for the moment.
70+
}
71+
```
72+
73+
> [!WARNING]
74+
> ## Note from the developer:
75+
> It should be mentioned that not all of the codebase is formatted this way. This standard guideline has been introduced 2 years after the project has started, and the lack of any guideline has resulted in the codebase looking fragmented, inconsistent, and very different in some portions due to differing coding styles among developers. This is completely my fault, and it has accumulated technical debt over the years. Although the current state isn't formatted consistently, the guideline is meant to slowly evolve the library into a much simpler version that's approachable to anybody trying to contribute and read through the code.
3276
3377

3478
## I want to add a new technique, how would I do that?
3579
There's a few steps that should be taken:
3680
1. Make sure to add the technique name in the enums of all the techniques in the appropriate place.
3781
2. Add the technique function itself in the technique section of the library. Make sure to add it in the right place, as there's preprocessor directives for each platform (Linux, Windows, and Apple)
3882
3. Add the technique in the technique table situated at the end of the header file. The score should be between 10 and 100. Although there are exceptions, it's advised to follow the aforementioned score range.
83+
4. Add it to the CLI's technique runner list.
3984

4085

4186
## I want to make a major change to the library

src/vmaware.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,7 +2526,6 @@ struct VM {
25262526
constexpr u32 HYPERVISOR_MASK = (1u << 31);
25272527

25282528
if (ecx & HYPERVISOR_MASK) {
2529-
std::cout << "reached\n\n\n\n";
25302529
if (util::hyper_x() == HYPERV_ARTIFACT_VM) {
25312530
return false;
25322531
}
@@ -2593,8 +2592,7 @@ struct VM {
25932592
debug("BOCHS_CPU: technique 1 found");
25942593
return core::add(brands::BOCHS);
25952594
}
2596-
}
2597-
else if (amd) {
2595+
} else if (amd) {
25982596
// technique 2: "processor" should have a capital P
25992597
if (brand == "AMD Athlon(tm) processor") {
26002598
debug("BOCHS_CPU: technique 2 found");
@@ -11468,11 +11466,9 @@ struct VM {
1146811466
// above 150 to get to 100%
1146911467
if (points >= threshold) {
1147011468
percent = 100;
11471-
}
11472-
else if (points >= 100) {
11469+
} else if (points >= 100) {
1147311470
percent = 99;
11474-
}
11475-
else {
11471+
} else {
1147611472
percent = static_cast<u8>(std::min<u16>(points, 99));
1147711473
}
1147811474

0 commit comments

Comments
 (0)