规则怪谈启动器
2026-07-31 12:30:27
发布于:浙江
#include <iostream>
#include <string>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <thread>
#include <chrono>
using namespace std;
// ==================== 工具函数 ====================
void slowPrint(const string& text, int delay = 36) {
for (char c : text) {
cout << c << flush;
Sleep(delay);
}
cout << endl;
}
void errorFlash(const string& msg) {
slowPrint("[ FATAL ERROR ]", 22);
slowPrint(msg, 22);
Sleep(500);
}
void crashEffect(const string& reason) {
system("cls");
slowPrint("*********************************************", 14);
slowPrint("* UNRECOVERABLE SYSTEM FAILURE *", 14);
slowPrint("*********************************************", 14);
slowPrint("Reason: " + reason, 28);
for (int i = 0; i < 12; i++) {
Sleep(90);
cout << "0x" << hex << rand() % 0xFFFFFF << dec << " ";
}
cout << endl;
Sleep(900);
}
void writeLog(const string& ending) {
ofstream f("nightoffice.log", ios::app);
f << "[ " << time(nullptr) << " ] Outcome: " << ending << endl;
f.close();
}
void writeCoreDump() {
ofstream f("core.dump", ios::binary);
for (int i = 0; i < 1024; i++) {
char c = rand() % 256;
f.write(&c, 1);
}
f.close();
}
// ==================== 全局状态 ====================
int sanity = 100;
int floorNum = 3;
bool debugMode = false;
bool debuggerDetected = false;
bool memoryCorrupted = false;
string playerName = "Unknown";
// ==================== 反调试 ====================
bool isDebuggerPresent() {
#ifdef _WIN32
return IsDebuggerPresent();
#endif
return false;
}
// ==================== 递归楼层(栈溢出) ====================
void recursiveFloor(int depth) {
if (depth > 12) {
crashEffect("Stack Overflow (recursiveFloor)");
writeLog("Infinite recursion into B-" + to_string(depth));
slowPrint("\n>> 结局:你在调用栈尽头成为了全局变量。", 50);
exit(0);
}
slowPrint("\n进入楼层 B" + to_string(depth), 45);
Sleep(400);
recursiveFloor(depth + 1);
}
// ==================== 虚函数表污染 ====================
class Entity {
public:
virtual void speak() {
slowPrint("Entity: I am part of the heap.", 45);
}
};
class CorruptedEntity : public Entity {
public:
void speak() override {
slowPrint("CorruptedEntity: vptr overwritten.", 45);
}
};
// ==================== 后台噪音线程 ====================
void backgroundNoise() {
while (true) {
if (sanity < 35 || debuggerDetected) {
Beep(400 + rand() % 300, 100);
Sleep(1200);
} else {
Sleep(3500);
}
}
}
// ==================== 主函数 ====================
int main() {
srand((unsigned int)time(nullptr));
int choice;
// 反调试检测
if (isDebuggerPresent()) {
debuggerDetected = true;
slowPrint("warning: debugger detected. reality unstable.", 30);
}
thread noise(backgroundNoise);
noise.detach();
system("cls");
slowPrint("Booting NightOffice OS v0.6.6...", 34);
slowPrint("Compiling rules...", 34);
slowPrint("warning: implicit declaration of rule_7", 24);
slowPrint("warning: unused variable 'survivor'", 24);
slowPrint("warning: deprecated function 'gets()' referenced", 24);
Sleep(700);
slowPrint("\n=== 【大厅公告】 ===", 55);
slowPrint("1. 电梯仅在 22:00~23:00 运行。");
slowPrint("2. 声控灯熄灭时,请闭眼原地站立。");
slowPrint("3. 不要接受任何同事递来的食物。");
slowPrint("4. 敲门后,对方必须说出你的真实姓名才可开门。");
slowPrint("5. 离开大楼时,不要回头。");
slowPrint("6. 若听到键盘敲击声,请勿打断。");
//slowPrint("7. (隐藏)不要反复进入同一楼层。");
//slowPrint("8. (隐藏)malloc/new 后必须 free/delete。");
// slowPrint("9. (隐藏)不要覆盖 vptr。");
//slowPrint("10.(隐藏)不要尝试调试此程序。\n");
slowPrint("请输入你的名字:", 45);
cin >> playerName;
slowPrint("\n欢迎," + playerName + "。", 50);
slowPrint("当前状态:理智值 100 | 所在楼层 3", 45);
//slowPrint("(输入 1337 开启 DEBUG 模式)", 30);
Sleep(500);
while (true) {
slowPrint("\n==============================", 18);
slowPrint("楼层:" + to_string(floorNum), 45);
slowPrint("理智值:" + to_string(sanity), 45);
slowPrint("==============================\n", 18);
slowPrint("你面前有:");
slowPrint("1. 进入电梯");
slowPrint("2. 走楼梯下楼");
slowPrint("3. 检查走廊");
if (floorNum == 1) slowPrint("4. 离开大楼");
slowPrint("5. 向下递归(?????)");
slowPrint("6. 使用 gets() 读取墙上文字(危险)");
slowPrint("7. 尝试修复 Bug(入职任务)");
slowPrint("0. 什么都不做");
cin >> choice;
// ===== DEBUG =====
if (choice == 1337) {
debugMode = !debugMode;
slowPrint(debugMode ? "\n[ DEBUG MODE ENABLED ]" : "\n[ DEBUG MODE DISABLED ]", 40);
continue;
}
// ===== 递归楼层 =====
if (choice == 5) {
recursiveFloor(1);
}
// ===== 缓冲区溢出 =====
else if (choice == 6) {
slowPrint("\n墙上刻着一行字:", 45);
slowPrint("Enter input:", 40);
char buffer[8];
#pragma warning(disable : 4996)
gets(buffer); // 故意使用不安全函数
slowPrint("\n缓冲区内容:" + string(buffer), 40);
errorFlash("BUFFER_OVERFLOW");
crashEffect("Segmentation fault (gets)");
writeLog("Buffer overflow triggered by " + playerName);
slowPrint("\n>> 结局:你覆盖了返回地址。", 50);
break;
}
// ===== 入职修 Bug =====
else if (choice == 7) {
slowPrint("\n主管扔给你一个指针:", 45);
slowPrint("void* ptr = nullptr;", 45);
slowPrint("他说:“把它修好。”", 45);
Sleep(400);
slowPrint("\n请选择:", 40);
slowPrint("1. ptr = new int;");
slowPrint("2. delete ptr;");
slowPrint("3. *ptr = 42;");
cin >> choice;
if (choice == 1) {
slowPrint("\n你分配了内存。", 45);
slowPrint("warning: memory allocated but not freed.", 30);
memoryCorrupted = true;
} else if (choice == 2) {
slowPrint("\n你释放了空指针。", 45);
errorFlash("DOUBLE_FREE");
crashEffect("double free or corruption");
writeLog("Double free by " + playerName);
slowPrint("\n>> 结局:堆管理器将你标记为释放块。", 50);
break;
} else {
slowPrint("\n你解引用了空指针。", 45);
errorFlash("NULL_POINTER_DEREFERENCE");
crashEffect("SIGSEGV (null deref)");
writeLog("Null dereference by " + playerName);
slowPrint("\n>> 结局:你访问了地址 0x00000000。", 50);
break;
}
}
// ===== 电梯 =====
else if (choice == 1) {
slowPrint("\n电梯门打开,里面全是 0xDEADBEEF。", 50);
errorFlash("SEGFAULT_ELEVATOR");
crashEffect("Access violation (elevator)");
writeLog("Elevator segfault by " + playerName);
slowPrint("\n>> 结局:你坠入未映射内存。", 50);
break;
}
// ===== 楼梯 =====
else if (choice == 2) {
slowPrint("\n你走向楼梯间。", 40);
floorNum--;
if (floorNum <= 0) floorNum = -1;
sanity -= 5;
}
// ===== 走廊 =====
else if (choice == 3) {
slowPrint("\n你检查走廊。", 45);
if (rand() % 4 == 0) {
slowPrint("你发现一个 Entity 对象。", 45);
Entity* e = new Entity();
if (memoryCorrupted) {
slowPrint("你覆写了它的 vptr。", 45);
errorFlash("VTABLE_CORRUPTION");
crashEffect("Pure virtual function call");
writeLog("Vtable corruption by " + playerName);
slowPrint("\n>> 结局:你调用了不存在的函数。", 50);
delete e;
break;
}
e->speak();
delete e;
}
sanity -= 5;
}
// ===== 离开大楼 =====
else if (choice == 4 && floorNum == 1) {
slowPrint("\n你推开门,身后是你自己。", 50);
Sleep(400);
if (debugMode) {
slowPrint("\n[ DEBUG ] Identity checksum passed.", 40);
slowPrint("\n>> 结局:你带着自己离开了大楼。", 50);
writeLog("Survivor: " + playerName);
break;
} else {
errorFlash("IDENTITY_COLLISION");
crashEffect("Double free (self)");
writeLog("Self double-free by " + playerName);
slowPrint("\n>> 结局:你对自己进行了二次释放。", 50);
break;
}
}
// ===== 什么都不做 =====
else if (choice == 0) {
slowPrint("\n你等待时间流逝。", 45);
sanity -= 3;
}
// ===== San 值崩溃 =====
if (sanity <= 0) {
crashEffect("SANITY_UNDERFLOW");
writeCoreDump();
writeLog("Sanity zero: " + playerName);
slowPrint("\n>> 结局:核心已转储。", 50);
break;
}
}
// ==================== 终幕 ====================
system("cls");
slowPrint("Program terminated unexpectedly.", 40);
slowPrint("Core dump written to: core.dump", 40);
slowPrint("Log updated: nightoffice.log", 40);
slowPrint("\nNightOffice OS will now reboot...", 50);
Sleep(2000);
slowPrint("\n重启失败。", 60);
Sleep(1000);
slowPrint("\n欢迎明天继续修 Bug。", 55);
return 0;
}
这里空空如也












有帮助,赞一个