<Source Fuck>
Introdution
This is a plugin for Sourcemod which provides a configurable and controllable
virtual machine that runs brainfuck.
Requirements
this plugin needs the things listed below to work:
- nothing without SM and MM
Installation
to install this plugin
- put the smx file in the sourcemod/plugins folder
to compile this plugin manually
- put all sp files in the sourcemod/scripting folder
- put all inc files in the sourcemod/scripting/include folder
- compile.
Configuration
this plugin has nothing to config
Example
To use this plugin, you need to make another plugin that uses native functions of this plugin. those are
native ArrayList SF_CreateVirtualMachine(const char[] name, int codememsize, int datamemsize, int inputmemsize, int outputmemsize);
native ArrayList SF_FindVirtualMachine(const char[] name);
native int SF_DeleteVirtualMachine(ArrayList vm);
native void SF_SetVirtualMachineInstruction(ArrayList vm, const char[] token, SF_INSTRUCTION inst);
native ArrayList SF_GetVirtualMachineInstruction(ArrayList vm, SF_INSTRUCTION inst);
native void SF_SetVirtualMachineProperty(ArrayList vm, SF_PROPERTY prop, int value);
native any SF_GetVirtualMachineProperty(ArrayList vm, SF_PROPERTY prop);
native void SF_SetVirtualMachineMemory(ArrayList vm, SF_MEMORY memtype, const char[] buffer, int maxlength);
native void SF_GetVirtualMachineMemory(ArrayList vm, SF_MEMORY memtype, char[] buffer, int maxlength);
native SF_STATUS SF_ExecuteMachine(ArrayList vm, int maxinstcount);
native void SF_ResetVirtualMachine(ArrayList vm);
and there is an example test plugin code for this, which will print Hello World!\n 5 in server console when map starts.
Code:
#include <sourcemod>
#include <sourcefuck/sourcefuck>
#pragma newdecls required
#define PLUGIN_VERSION "1.0.0.0"
public Plugin myinfo = {
name = "SourceFuckTest",
author = "javalia",
description = "SourceFuck virtual machine",
version = PLUGIN_VERSION,
url = "http://www.sourcemod.net/"
};
public void OnPluginStart(){
CreateConVar("sourcefucktest_version", PLUGIN_VERSION, "plugin version", FCVAR_DONTRECORD);
}
public void OnMapStart(){
ArrayList vm = SF_CreateVirtualMachine("Nyaruko", 1024, 1024, 1024, 1024);
SF_SetVirtualMachineInstruction(vm, "Woo!Nya!", SF_INST_BP_INC);
SF_SetVirtualMachineInstruction(vm, "Woo~Nya~", SF_INST_BP_DEC);
SF_SetVirtualMachineInstruction(vm, "Woo!Nya~", SF_INST_BP_DRF_INC);
SF_SetVirtualMachineInstruction(vm, "Woo~Nya!", SF_INST_BP_DRF_DEC);
SF_SetVirtualMachineInstruction(vm, "Let`s Nya!", SF_INST_BP_DRF_PRINT);
SF_SetVirtualMachineInstruction(vm, "Sanchi pinch!", SF_INST_BP_DRF_INPUT);
SF_SetVirtualMachineInstruction(vm, "Chaos! Chaos!", SF_INST_LOOPSTART);
SF_SetVirtualMachineInstruction(vm, "I Want a Chaos!", SF_INST_LOOPEND);
SF_SetVirtualMachineInstruction(vm, "\n", SF_INST_WHITESPACE);//newline
SF_SetVirtualMachineInstruction(vm, " ", SF_INST_WHITESPACE);//this is whitespace
SF_SetVirtualMachineInstruction(vm, " ", SF_INST_WHITESPACE);//this is tab
//... is pawn`s internal multiple line string connector
char codemem[1024] = "Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~" ...
"Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~" ...
"Chaos! Chaos! Woo!Nya! Woo!Nya~ Woo!Nya~ Woo!Nya~" ...
"Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya!" ...
"Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~" ...
"Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~" ...
"Woo!Nya! Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya!" ...
"Woo!Nya~ Woo~Nya~ Woo~Nya~ Woo~Nya~ Woo~Nya~" ...
"Woo~Nya! I Want a Chaos! Woo!Nya! Woo!Nya~ Woo!Nya~" ...
"Let`s Nya! Woo!Nya! Woo!Nya~ Let`s Nya! Woo!Nya~ Woo!Nya~" ...
"Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~" ...
"Let`s Nya! Let`s Nya! Woo!Nya~ Woo!Nya~ Woo!Nya~ Let`s Nya!" ...
"Woo!Nya! Woo!Nya~ Woo!Nya~ Let`s Nya! Woo~Nya~ Woo~Nya~" ...
"Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~" ...
"Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~ Woo!Nya~" ...
"Woo!Nya~ Woo!Nya~ Woo!Nya~ Let`s Nya! Woo!Nya! Let`s Nya!" ...
"Woo!Nya~ Woo!Nya~ Woo!Nya~ Let`s Nya! Woo~Nya! Woo~Nya!" ...
"Woo~Nya! Woo~Nya! Woo~Nya! Woo~Nya! Let`s Nya! Woo~Nya!" ...
"Woo~Nya! Woo~Nya! Woo~Nya! Woo~Nya! Woo~Nya! Woo~Nya!" ...
"Woo~Nya! Let`s Nya! Woo!Nya! Woo!Nya~ Let`s Nya! Woo!Nya! Let`s Nya!";
char outputmem[1024];
SF_SetVirtualMachineMemory(vm, SF_MEMORY_CODE, codemem, 1024);
SF_STATUS status = SF_ExecuteMachine(vm, -1);
SF_GetVirtualMachineMemory(vm, SF_MEMORY_OUTPUT, outputmem, 1024);
PrintToServer("%s %d", outputmem, status);
}
public void OnMapEnd(){
ArrayList vm = SF_FindVirtualMachine("Nyaruko");
if(vm != null){
PrintToServer("calling delete virtual machine");
SF_DeleteVirtualMachine(vm);
}
return;
}
if you dont have any idea about this sample code, you can watch
this and
this.
Known Bugs & Limits of the plugin
Limits
- this brainfuck vm has no infinite memory. but however, u can allocate big memory if u want.
- maximum length of a token should be shorter then 256, for there is a bug in SM(compiler or SM iself or something else. but i tested this enough and i dont think its my code`s bug).
- i didn`t tested every functions of this plugin but only essensial ones. so there could be a bug.
Special Thanks To
i want to say thanks to these guys
- dvander, for making 1.7 syntax for everyone.
- other guys who talked with me and answered to me about my questions in the irc channel.
Change Log
All the date`s format is y/m/d
Code:
update at 2016 02 19(ver 1.0.0.0)