Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/elrygh/secure-godot


https://github.com/elrygh/secure-godot

Last synced: 18 days ago
JSON representation

Awesome Lists containing this project

README

        

Here's a step-by-step guide to disable specific command-line arguments in **game builds**, without affecting the Godot editor:

---

### **1. Understand the Goal**
We want to:
- Retain full functionality in the Godot editor binary for development.
- Customize and rebuild export templates so that the exported game binaries do not include debug-related command-line options like `--help` or `--debug`.

This is achieved by modifying the **export template code paths** and compiling templates with `tools=no`.

---

### **2. Prerequisites**
Follow the [Godot official guide for compiling on Windows](https://docs.godotengine.org/en/latest/contributing/development/compiling/compiling_for_windows.html) and ensure you have installed:
1. **Visual Studio 2022** with the "Desktop Development with C++" workload.
2. **Python 3.8+** with SCons:
```bash
python -m pip install scons
```
3. **Git** to clone the Godot repository.

---

### **3. Modify the Command-Line Parsing Code**
1. Open the Godot source code:
```bash
git clone https://github.com/godotengine/godot.git
cd godot
git checkout 4.3-stable
```

2. Open `main/main.cpp` in your code editor.

3. Locate the section responsible for parsing command-line arguments. Typically, it looks like this:
```cpp
for (int i = 1; i < argc; i++) {
String arg = argv[i];
if (arg == "--help") {
print_help();
return 0;
}
// Other arguments like debug options
}
```

4. Comment out unwanted arguments **only in export templates**.

```cpp
for (int i = 1; i < argc; i++) {
String arg = argv[i];

// Disable debug-related options in exported builds.
//if (arg == "--help") {
// print_help();
// return 0;
//}

// Retain essential or custom arguments like --fullscreen
if (arg == "--fullscreen" || arg.begins_with("--")) {
OS::get_singleton()->set_fullscreen(true);
}
}
```

5. Save the changes.

---

### **4. Compile the Export Templates**
1. Open the **x64 Native Tools Command Prompt** from Visual Studio.

2. Navigate to the Godot source directory:
```bash
cd path\to\godot
```

3. Compile the export templates with `tools=no`:
- **Debug template**:
```bash
scons platform=windows target=release_debug tools=no -j8
```
- **Release template**:
```bash
scons platform=windows target=release tools=no -j8
```

4. The compiled templates will appear in the `bin/` directory:
- `godot.windows.opt.debug.64.exe` (debug export template).
- `godot.windows.opt.release.64.exe` (release export template).

---

### **5. Replace Default Export Templates**
1. Locate the export templates in your Godot installation:
- Default location: `C:\Users\\AppData\Roaming\Godot\templates\4.x-stable`.
2. Replace the default Windows templates with your custom-built binaries.

Alternatively:
- Use **Editor > Manage Export Templates** to configure a custom path for your templates.

---

### **6. Test the Exported Game**
1. In Godot, export your project using the custom templates.
2. Run the exported binary and test:
- Verify that debug options like `--help` or `--debug` are no longer functional.
- Confirm that essential options (e.g., `--fullscreen`) still work as expected.

---

### **7. Notes**
- These changes affect only the **exported game binaries**, leaving the editor binary fully functional.
- If you ever update Godot or use a newer version, you'll need to reapply these changes and rebuild the export templates.

This approach ensures a clean separation between the development environment and production builds, enhancing security for your shipped games.