Skip to content

Instantly share code, notes, and snippets.

@rtldg
Created August 17, 2024 22:23
Show Gist options
  • Select an option

  • Save rtldg/2a27e8a744d0927f1202e0f9da5a7010 to your computer and use it in GitHub Desktop.

Select an option

Save rtldg/2a27e8a744d0927f1202e0f9da5a7010 to your computer and use it in GitHub Desktop.
public void OnPluginStart()
{
char output[0xFFFF], data[0xFFFF];
int outputpos;
int pointer;
char code[] = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";
for (int i; code[i]; i++) {
switch (code[i]) {
case '>': pointer++
case '<': pointer--;
case '+': data[pointer]++;
case '-': data[pointer]--;
case '.': output[outputpos++] = data[pointer];
case ',': SetFailState("Receiving input to brainfuck is not implemented");
case '[':
if (!data[pointer])
{
int depth, c;
while ((c = code[++i]))
{
if (c == '[')
depth++;
else if (c == ']' && depth != 0)
depth--;
else if (c == ']' && depth == 0)
break;
}
}
case ']':
if (data[pointer])
{
int depth, c;
while ((c = code[--i]))
{
if (c == ']')
depth++;
else if (c == '[' && depth != 0)
depth--;
else if (c == '[' && depth == 0)
break;
}
}
}
}
PrintToServer("%s", output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment