Skip to content

Instantly share code, notes, and snippets.

Avatar

JackMacWindows MCJack123

View GitHub Profile
@MCJack123
MCJack123 / string_pack.lua
Created Oct 21, 2021
Backport of string.pack for Lua 5.2 [WIP]
View string_pack.lua
--local expect = require "cc.expect".expect
local expect = dofile "/rom/modules/main/cc/expect.lua".expect
local ByteOrder = {BIG_ENDIAN = 1, LITTLE_ENDIAN = 2}
local isint = {b = 1, B = 1, h = 1, H = 1, l = 1, L = 1, j = 1, J = 1, T = 1}
local packoptsize_tbl = {b = 1, B = 1, x = 1, h = 2, H = 2, f = 4, j = 4, J = 4, l = 8, L = 8, T = 8, d = 8, n = 8}
local function round(n) if n % 1 >= 0.5 then return math.ceil(n) else return math.floor(n) end end
local function floatToRawIntBits(f)
@MCJack123
MCJack123 / jscc.mm
Created Jul 20, 2021
JavaScriptCore integration for CraftOS-PC (bad code)
View jscc.mm
#import <JavaScriptCore/JavaScriptCore.h>
#include <CraftOS-PC.hpp>
#include <math.h>
#include <float.h>
#include <stdarg.h>
static JSContext * ctx;
static JSValue * Function;
static int jsc_call(lua_State *L);
@MCJack123
MCJack123 / UTFString.lua
Last active Jul 16, 2021
UTF string type for Lua 5.3
View UTFString.lua
local expect = require "cc.expect"
local UTFString = {}
local UTFString_mt = {__index = UTFString, __name = "UTFString"}
local function toUTF8(s)
-- convert from ANSI if the string is invalid in UTF-8
local ss = ""
local iter, invar, i = utf8.codes(s)
local ok, c
@MCJack123
MCJack123 / battleship.lua
Last active Jul 15, 2021
Battleship game for ComputerCraft
View battleship.lua
local mask = {
hasShip = 1,
hover = 2,
hit = 4,
miss = 8,
}
local ships = {Carrier = 5, Battleship = 4, Destroyer = 3, Submarine = 3, ["Patrol Boat"] = 2}
local rednetConnection = {
@MCJack123
MCJack123 / on-writing-an-os.md
Last active Jun 29, 2021
On Writing a ComputerCraft OS
View on-writing-an-os.md

On Writing a ComputerCraft OS

One of the most common projects I've seen for ComputerCraft is to write an operating system. People look at the limited command-line interface that CraftOS provides, and think, "I want this to work like my normal computer does!" Time and time again, a new post pops up on the ComputerCraft forums or Discord either announcing an OS, or asking for help with an OS, or releasing an OS. Usually, there are some very obvious flaws in these "OS"es, ranging from poor design choices, to overstating what they are and underdelivering. There are many common misunderstandings and undersights that newbie developers run into when writing an operating system, and these end up creating mediocre products at best.

A Critical Distinction

The term "OS" is thrown around a lot, and in my opinion it's very overused. According to [Wikipedia]: "An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs." However, m

@MCJack123
MCJack123 / lua5.1-ropes.patch
Last active Jun 19, 2021
Rope concatenation for Lua 5.1 inspired by SquidDev/Cobalt
View lua5.1-ropes.patch
diff -ruN lua-5.1.5-clean/src/Makefile lua-5.1.5-ropes/src/Makefile
--- lua-5.1.5-clean/src/Makefile 2012-02-13 15:41:22.000000000 -0500
+++ lua-5.1.5-ropes/src/Makefile 2021-06-19 08:03:46.000000000 -0400
@@ -135,7 +135,7 @@
ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h lstring.h \
ltable.h lundump.h lvm.h
-ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \
+ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h lstring.h ltm.h \
lzio.h lmem.h lundump.h
@MCJack123
MCJack123 / rawshell.lua
Last active Oct 19, 2021
Remote shell program for ComputerCraft featuring passwords, encryption, and background processing
View rawshell.lua
-- MIT License
--
-- Copyright (c) 2021 JackMacWindows
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
@MCJack123
MCJack123 / rawterm.lua
Last active Jul 15, 2021
CraftOS-PC raw mode client/server API for ComputerCraft with test program
View rawterm.lua
--- rawterm.lua - CraftOS-PC raw mode protocol client/server API
-- By JackMacWindows
--
-- @module rawterm
--
-- This API provides the ability to host terminals accessible from remote
-- systems, as well as to render those terminals on the screen. It uses the raw
-- mode protocol defined by CraftOS-PC to communicate between client and server.
-- This means that this API can be used to host and connect to a CraftOS-PC
-- instance running over a WebSocket connection (using an external server
@MCJack123
MCJack123 / ScoreSaberGetMap.user.js
Last active Sep 5, 2021
Small UserScript to add download links to ScoreSaber leaderboard pages (requires GreaseMonkey/TamperMonkey/*Monkey)
View ScoreSaberGetMap.user.js
// ==UserScript==
// @name ScoreSaberGetMap
// @version 2
// @grant none
// @match *://scoresaber.com/leaderboard/*
// ==/UserScript==
let box = Array.from(document.getElementsByClassName("box has-shadow")).filter(e => e.innerHTML.indexOf("ID:") != -1)[0];
if (box !== null && box !== undefined) {
let id = box.innerHTML.match(/ID: *<b>([0-9A-F]+)<\/b>/)[1];
@MCJack123
MCJack123 / ccbot.js
Last active May 8, 2021
Discord bot that executes Lua code in CraftOS-PC, and returns a screenshot of the result
View ccbot.js
// Requires https://gist.github.com/MCJack123/4eb02b57de9fcb9c6e62b9b459ada8e6
// Extract env-clean.tar into env-clean next to this file
const { Client, MessageAttachment } = require('discord.js');
const exec = require('child_process').exec;
const fs = require("fs-extra");
const http = require("https");
const client = new Client();
const init_script = (script, author) => `
term.clear()
term.setCursorPos(1, 1)