MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / sm_WriteFile

Function sm_WriteFile

core/logic/smn_filesystem.cpp:1132–1168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1130}
1131
1132static cell_t sm_WriteFile(IPluginContext *pContext, const cell_t *params)
1133{
1134 OpenHandle<FileObject> file(pContext, params[1], g_FileType);
1135 if (!file.Ok())
1136 return 0;
1137
1138 cell_t *data;
1139 pContext->LocalToPhysAddr(params[2], &data);
1140
1141 switch (params[4]) {
1142 case 4:
1143 if (file->Write(data, sizeof(cell_t) * params[3]) != sizeof(cell_t) * size_t(params[3]))
1144 return 0;
1145 break;
1146
1147 case 2:
1148 for (cell_t i = 0; i < params[3]; i++) {
1149 int16_t v = data[i];
1150 if (file->Write(&v, sizeof(v)) != sizeof(v))
1151 return 0;
1152 }
1153 break;
1154
1155 case 1:
1156 for (cell_t i = 0; i < params[3]; i++) {
1157 int8_t v = data[i];
1158 if (file->Write(&v, sizeof(v)) != sizeof(v))
1159 return 0;
1160 }
1161 break;
1162
1163 default:
1164 return pContext->ThrowNativeError("Invalid size specifier (%d is not 1, 2, or 4)", params[4]);
1165 }
1166
1167 return 1;
1168}
1169
1170static cell_t sm_WriteFileString(IPluginContext *pContext, const cell_t *params)
1171{

Callers

nothing calls this directly

Calls 2

OkMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected