Created
January 4, 2025 20:10
-
-
Save Absolucy/b933fad25eb02a3a81fb0e22b92d5ac9 to your computer and use it in GitHub Desktop.
pure DM rust-g stub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This is a stub for the rust-g DLL, implemented in pure DM. | |
* It implements whatever functions were somewhat trivial to implement. | |
* Everything else just returns null and logs "UNIMPLEMENTED STUB: rustg_func_name" to world.log. | |
* | |
* This has been tested and can initialize + run on /tg/station code as of 1/4/2025 (commit 2df30547c27) | |
* Don't use this in production. The only reason this exists is to help Lummox reproduce bugs in SS13 codebases easier. | |
* | |
* You may need to also comment out a url_encode/decode override define in some codebases, usually in rust_g_overrides.dm or something. | |
*/ | |
#define RUSTG_STUB_UNSUPPORTED(name) \ | |
/proc/##name(...) { \ | |
world.log << "UNIMPLEMENTED STUB: " + #name; \ | |
return null; \ | |
} | |
/proc/rustg_get_version() | |
return "0.0.0 (stub)" | |
RUSTG_STUB_UNSUPPORTED(rustg_setup_acreplace) | |
RUSTG_STUB_UNSUPPORTED(rustg_setup_acreplace_with_options) | |
RUSTG_STUB_UNSUPPORTED(rustg_acreplace) | |
RUSTG_STUB_UNSUPPORTED(rustg_acreplace_with_replacements) | |
RUSTG_STUB_UNSUPPORTED(rustg_cnoise_generate) | |
RUSTG_STUB_UNSUPPORTED(rustg_dbp_generate) | |
RUSTG_STUB_UNSUPPORTED(rustg_dmi_strip_metadata) | |
RUSTG_STUB_UNSUPPORTED(rustg_dmi_create_png) | |
RUSTG_STUB_UNSUPPORTED(rustg_dmi_resize_png) | |
/proc/rustg_dmi_icon_states(fname) | |
var/icon/icon = icon(file("[fname]")) | |
return json_encode(icon_states(icon)) | |
#define rustg_file_read file2text | |
#define rustg_file_exists fexists | |
/proc/rustg_file_write(text, fname) | |
fdel("[fname]") | |
text2file("[text]", "[fname]") | |
/proc/rustg_file_append(text, fname) | |
text2file("[text]", "[fname]") | |
#define GET_FILE_LINES(fname) (splittext_char(file2text("[fname]"), "\n")) | |
/proc/rustg_file_get_line_count(fname) | |
return length(GET_FILE_LINES(fname)) | |
/proc/rustg_file_seek_line(fname, line) | |
var/list/lines = GET_FILE_LINES(fname) | |
if(length(lines) >= line) | |
return lines[line] | |
#undef GET_FILE_LINES | |
/proc/rustg_git_revparse(rev) | |
return sha1("meow") | |
/proc/rustg_git_commit_date(rev, format = "%F") | |
return time2text(world.realtime, "YYYY-MM-DD") | |
/proc/rustg_git_commit_date_head(rev, format = "%F") | |
return time2text(world.realtime, "YYYY-MM-DD") | |
#define RUSTG_HTTP_METHOD_GET "get" | |
#define RUSTG_HTTP_METHOD_PUT "put" | |
#define RUSTG_HTTP_METHOD_DELETE "delete" | |
#define RUSTG_HTTP_METHOD_PATCH "patch" | |
#define RUSTG_HTTP_METHOD_HEAD "head" | |
#define RUSTG_HTTP_METHOD_POST "post" | |
RUSTG_STUB_UNSUPPORTED(rustg_http_request_blocking) | |
RUSTG_STUB_UNSUPPORTED(rustg_http_request_async) | |
RUSTG_STUB_UNSUPPORTED(rustg_http_check_request) | |
#define RUSTG_JOB_NO_RESULTS_YET "NO RESULTS YET" | |
#define RUSTG_JOB_NO_SUCH_JOB "NO SUCH JOB" | |
#define RUSTG_JOB_ERROR "JOB PANICKED" | |
#pragma push | |
#pragma ignore unused_var | |
/proc/rustg_json_is_valid(json) | |
try | |
var/_ = json_decode("[json]") | |
return TRUE | |
catch | |
return FALSE | |
#pragma pop | |
/proc/rustg_log_write(fname, text, format) | |
if(format) | |
var/list/lines = splittext_char("[text]", "\n") | |
var/final_log = list() | |
for(var/idx = 1 to length(lines)) | |
var/line = lines[idx] | |
if(idx == 1) | |
var/timeofday = world.timeofday | |
var/time = time2text(timeofday, "YYYY-MM-DD hh:mm:ss") | |
var/deciseconds = "[round(timeofday % 10)]00" | |
final_log += "\[[time].[deciseconds]\] [line]" | |
else | |
final_log += " - [line]" | |
if(length(lines)) | |
text2file(jointext(final_log, "\n"), "[fname]") | |
else | |
text2file("[text]", "[fname]") | |
/proc/rustg_log_close_all() | |
world.log << "\[ STUB: rustg_log_close_all \]" | |
RUSTG_STUB_UNSUPPORTED(rustg_noise_get_at_coordinates) | |
RUSTG_STUB_UNSUPPORTED(rustg_noise_poisson_map) | |
RUSTG_STUB_UNSUPPORTED(rustg_sanitize_html) | |
/proc/rustg_sql_connect_pool(...) | |
var/static/return_json | |
if(isnull(return_json)) | |
return_json = json_encode(list("status" = "err", "data" = "stub not implemented")) | |
return return_json | |
/proc/rustg_sql_connected(...) | |
var/static/return_json | |
if(isnull(return_json)) | |
return_json = json_encode(list("status" = "offline")) | |
return return_json | |
#define rustg_sql_disconnect_pool rustg_sql_connected | |
RUSTG_STUB_UNSUPPORTED(rustg_sql_query_async) | |
RUSTG_STUB_UNSUPPORTED(rustg_sql_query_blocking) | |
RUSTG_STUB_UNSUPPORTED(rustg_sql_check_query) | |
/* This comment bypasses grep checks */ var/static/list/_rustg_stub_timers = list() | |
/proc/rustg_time_microseconds(id) | |
if(!_rustg_stub_timers[id]) | |
return 0 | |
return max(world.timeofday - _rustg_stub_timers[id], 0) * 100000 | |
/proc/rustg_time_milliseconds(id) | |
if(!_rustg_stub_timers[id]) | |
return 0 | |
return max(world.timeofday - _rustg_stub_timers[id], 0) * 100 | |
/proc/rustg_time_reset(id) | |
_rustg_stub_timers[id] = world.timeofday | |
/proc/rustg_unix_timestamp() | |
// magic number from this byond forum post: http://www.byond.com/forum/post/1400219#comment6981656 | |
return num2text((world.realtime + 9.46708e9) * 0.1, 16) | |
RUSTG_STUB_UNSUPPORTED(rustg_raw_read_toml_file) | |
RUSTG_STUB_UNSUPPORTED(rustg_read_toml_file) | |
RUSTG_STUB_UNSUPPORTED(rustg_raw_toml_encode) | |
RUSTG_STUB_UNSUPPORTED(rustg_toml_encode) | |
#define RUSTG_SOUNDLEN_SUCCESSES "successes" | |
#define RUSTG_SOUNDLEN_ERRORS "errors" | |
RUSTG_STUB_UNSUPPORTED(rustg_sound_length) | |
RUSTG_STUB_UNSUPPORTED(rustg_sound_length_list) | |
#undef RUSTG_STUB_UNSUPPORTED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment