尝试重写 dofile 文件流成功
This commit is contained in:
parent
6237ecd17f
commit
b2d797c480
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容
|
||||
// Windows 头文件
|
||||
#include <windows.h>
|
||||
|
|
@ -8,3 +8,6 @@
|
|||
|
||||
#include "squirrel.h"
|
||||
#include "MinHook.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -111,6 +111,7 @@ typedef void* (SQDOFILEFunc)(uint32_t v, const wchar_t* filename, bool retval, b
|
|||
static SQDOFILEFunc* SQDOFILE = (SQDOFILEFunc*)0x1356240;
|
||||
|
||||
|
||||
typedef void*(*SQFILE)();
|
||||
//SQ_io_file_lexfeed_编码
|
||||
//typedef int(LSQLEXREADFUNC)(int n);
|
||||
typedef int(*LSQLEXREADFUNC)(int n);
|
||||
|
|
@ -119,7 +120,7 @@ static LSQLEXREADFUNC SQ_io_file_lexfeed_UCS2_BE = (LSQLEXREADFUNC)0x1356050;
|
|||
static LSQLEXREADFUNC SQ_io_file_lexfeed_UCS2_LE = (LSQLEXREADFUNC)0x1356020;
|
||||
static LSQLEXREADFUNC SQ_io_file_lexfeed_UTF8 = (LSQLEXREADFUNC)0x1355F90;
|
||||
//SQfopen
|
||||
typedef void* (SQfopenFunc)(const wchar_t* filename, const wchar_t* type);
|
||||
typedef SQFILE* (SQfopenFunc)(const wchar_t* filename, const wchar_t* type);
|
||||
static SQfopenFunc* SQfopen = (SQfopenFunc*)0x1355DC0;
|
||||
//SQfread
|
||||
typedef int(SQfreadFunc)(void* buffer, int a, int b, void* file);
|
||||
|
|
|
|||
37
test/函数块.cpp
37
test/函数块.cpp
|
|
@ -240,7 +240,9 @@ int GetEquAddr(int addr)
|
|||
//¼ÓÔØ
|
||||
static int SQloadfile(uint32_t v, const wchar_t* filename, bool printerror)
|
||||
{
|
||||
void* file = SQfopen(filename, L"rb");
|
||||
SQFILE* file = SQfopen(filename, L"rb+");
|
||||
//FILE* file;
|
||||
//file = fopen(filename, "rb");
|
||||
int ret;
|
||||
unsigned short us;
|
||||
unsigned char uc;
|
||||
|
|
@ -283,18 +285,26 @@ static int SQloadfile(uint32_t v, const wchar_t* filename, bool printerror)
|
|||
default: SQfseek(file, 0, 2); break; // ascii
|
||||
}
|
||||
|
||||
const char *add = "newstr";
|
||||
int prevpos = SQftell(file);
|
||||
char* nstr = (char*)"IIIAAAB <- 6648";
|
||||
//SQwrite(&add, 1, sizeof(add), file);
|
||||
SQwrite(nstr, sizeof(nstr), strlen(nstr), file);
|
||||
|
||||
SQfseek(file, 0, 1);
|
||||
int length = SQftell(file);
|
||||
SQfseek(file, prevpos, 2);
|
||||
char temp[256];
|
||||
SQwrite(&add, 1, sizeof(add), file);
|
||||
SQfread(&temp, length + 10, sizeof(temp), file);
|
||||
std::cout << temp << std::endl;
|
||||
|
||||
SQfseek(file, 0, 2);
|
||||
std::cout << "lenth:" << length << std::endl;
|
||||
//char temp[256];
|
||||
char* temp = new char[length];
|
||||
//SQwrite(&add, 1, sizeof(add), file);
|
||||
SQfread(temp, sizeof(temp), length, file);
|
||||
temp[length] = '\0';
|
||||
printf(temp);
|
||||
printf("\n");
|
||||
//std::cout << temp << std::endl;
|
||||
|
||||
//char* temp = new char[16 * 4];
|
||||
|
||||
SQfseek(file, 0, 2);
|
||||
if (SQ_Compile(v, func, file, filename, printerror) >= 0)
|
||||
{
|
||||
SQ__Fclose(file);
|
||||
|
|
@ -361,7 +371,6 @@ void RegisterNutApi(const wchar_t* funcName, void* funcAddr, uint32_t v)
|
|||
static int sq_Test(uint32_t v)
|
||||
{
|
||||
//sq_pushinteger(v, n1);
|
||||
SQdofile(v, L"1.cpp", false, false);
|
||||
return 0;
|
||||
}
|
||||
//¶ÁÈËÎï »ò ×°±¸ÊôÐÔ
|
||||
|
|
@ -618,6 +627,14 @@ static int LDofile(uint32_t v)
|
|||
{
|
||||
SQGetString(v, 2, &n1);
|
||||
SQPopTop(v);
|
||||
/*
|
||||
size_t len = wcslen(n1) + 1;
|
||||
size_t converted = 0;
|
||||
char* CStr;
|
||||
CStr = (char*)malloc(len * sizeof(char));
|
||||
wcstombs_s(&converted, CStr, len, n1, _TRUNCATE);
|
||||
*/
|
||||
|
||||
SQdofile(v, n1, false, false);
|
||||
SQPushBool(v, true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue